Skip to content

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

Merged
merged 10 commits into from
Dec 5, 2021

Conversation

skwirskj
Copy link
Contributor

@skwirskj skwirskj commented Nov 30, 2021

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.
@phofl
Copy link
Member

phofl commented Nov 30, 2021

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.
@jreback jreback added this to the 1.4 milestone Dec 2, 2021
@jreback jreback added the metadata _metadata, .attrs label Dec 2, 2021
Copy link
Contributor

@jreback jreback left a 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)

Copy link
Contributor

@jreback jreback left a 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"]
Copy link
Contributor

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.
@jreback jreback merged commit 1fe373f into pandas-dev:master Dec 5, 2021
@jreback
Copy link
Contributor

jreback commented Dec 5, 2021

thanks @skwirskj

@skwirskj
Copy link
Contributor Author

skwirskj commented Dec 5, 2021

No problem @jreback thank you for your help!

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

Successfully merging this pull request may close these issues.

BUG: DataFrame attributes are lost after specifying dtype for select columns
3 participants