-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
44414 data frame attributes not propagating with astype #44680
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
Conversation
skwirskj
commented
Nov 30, 2021
•
edited
Loading
edited
- closes BUG: DataFrame attributes are lost after specifying dtype for select columns #44414
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
Added a finalize call so that the metadata, specifically attributes, is retained when the datatype of one column is changed.
Passed previous DataFrame to finalize to ensure the correct attributes are being passed to the new DataFrame. Also added a test to test that calling astype passes attributes to the new DataFrame.
Couple of comments |
Changed description of bug fix to better explain what is being changed. Added more explicit varibale names in astype test to demonstrate the result and expected values.
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.
looks fine, small comment. we have a comprehensive test for methods, odd that this doesn't need changing (as it would not xpass)
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.
add a test for series as well. merge master and ping on green.
@@ -714,6 +714,19 @@ def test_astype_noncontiguous(self, index_slice): | |||
expected = df.iloc[index_slice] | |||
tm.assert_frame_equal(result, expected, check_dtype=False) | |||
|
|||
@pytest.mark.parametrize( | |||
"dtype", ["float", "int32", "int64", "string", "int16", "float32"] |
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.
can you use one of the fixtures in pandas/conftest.py instead
Added fixture use in both test_astype_retain_attrs functions in the DataFrame and Series testing files.
thanks @skwirskj |
No problem @jreback thank you for your help! |