-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
Conversation
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. |
Okay I'll do that now and also you said that we can chat about making a radioactive decay project. |
tardis/units/first_objective.py
Outdated
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) |
There was a problem hiding this comment.
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.
Also please change the name of the file. First_objective is not descriptive of the functionality. |
tardis/units/test.py
Outdated
""" | ||
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) |
There was a problem hiding this comment.
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.
@GOLoDovkA-A Are you planning on continuing with this PR? |
|
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
Checklist: