-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: DataFrame.stack losing EA dtypes with multi-columns and mixed dtypes #51691
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
BUG: DataFrame.stack losing EA dtypes with multi-columns and mixed dtypes #51691
Conversation
pandas/core/reshape/reshape.py
Outdated
if frame._is_homogeneous_type and is_extension_array_dtype( | ||
frame.dtypes.iloc[0] | ||
): | ||
subset = this[this.columns[loc]] |
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.
this.iloc[:, loc]
? i think in case where loc is a slice this avoids a copy
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.
updated. thanks
# TODO(EA2D): we get object dtype because DataFrame.values can't | ||
# be an EA | ||
expected = df.astype(object).stack("station") | ||
expected = ( |
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.
For this expected
could you construct without the astype(object)
e.g. pd.DataFrame(...)
?
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.
sure, updated.
Thanks @lukemanley |
doc/source/whatsnew/v2.1.0.rst
file if fixing a bug or adding a new feature.