Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subclassing pd.DataFrame with the addition of units #1069

Closed
wants to merge 6 commits into from

Conversation

a-golda
Copy link

@a-golda a-golda commented Mar 1, 2020

Simple extension of the Pandas.DataFrame that keeps track of units for the dataframe.
Basic information about methods of classes extention you can find here:
https://docs.python.org/2/tutorial/classes.html#inheritance
Basic information about methods of extention in pandas you can find here:
https://pandas.pydata.org/docs/development/extending.html#extension-types
Suitable example:
pandas-dev/pandas#10349
Much more suitable example:
https://tardis-sn.github.io/tardis/running/interaction/isotope_pd_subclass.html?highlight=isotopeabundances

Description

Created class UDataFrame inherited from pd.DataFrame which contains metadata about units. Thats only shows the use of constructing new subclasses of pd.DataFrame.

Motivation and Context

Pandas DataFrame isn't capable to store the units of the attributes. The other issue is that this information about units of attributes gets further vanished when we try to copy one dataframe into another.

How Has This Been Tested?

I've created an instances of UDataFrame copy them and checked the units.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

@wkerzendorf
Copy link
Member

good! did you follow any guidelines for the pandas subclassing - can you add this in the header of the PR? Any good PR should have tests and documentation as well. This is the next step to add.

@a-golda
Copy link
Author

a-golda commented Mar 1, 2020

Okay I'll do that now and also you said that we can chat about making a radioactive decay project.

@a-golda a-golda changed the title first_obj with UDataFrame added Subclassing pd.DataFrame with the addition of units Mar 1, 2020
Comment on lines 18 to 24
a = UDataFrame({"first_col": [1,2,3], "sec_col": [4, 5, 6]}, units=["cm", "mm"])

b = a.copy()

print(a, "Units for a:", a.units, " ",sep="\n"*2)

print("Units for b:", b.units,sep="\n"*2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines should be part of a separate unit test.

@marxwillia
Copy link
Contributor

Also please change the name of the file. First_objective is not descriptive of the functionality.

Comment on lines 5 to 15
"""
Test of class UDataFrame by making an instance and checking of units preservation after copying
"""

a = UDataFrame({"first_col": [1,2,3], "sec_col": [4, 5, 6]}, units=["cm", "mm"])

b = a.copy()

print(a, "Units for a:", a.units, " ",sep="\n"*2)

print("Units for b:", b.units,sep="\n"*2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please look at the other tardis unit tests to see how to write a proper unit test using pytest.

@marxwillia marxwillia self-assigned this Mar 3, 2020
@marxwillia
Copy link
Contributor

@GOLoDovkA-A Are you planning on continuing with this PR?

@a-golda
Copy link
Author

a-golda commented Mar 9, 2020

@GOLoDovkA-A Are you planning on continuing with this PR?
Yes, im still working with tests and trying to add new features

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants