Skip to content

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

Merged
merged 9 commits into from
Mar 9, 2023

Conversation

lukemanley
Copy link
Member

@lukemanley lukemanley added Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode ExtensionArray Extending pandas with custom dtypes or arrays. labels Feb 28, 2023
if frame._is_homogeneous_type and is_extension_array_dtype(
frame.dtypes.iloc[0]
):
subset = this[this.columns[loc]]
Copy link
Member

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

Copy link
Member Author

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 = (
Copy link
Member

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(...)?

Copy link
Member Author

Choose a reason for hiding this comment

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

sure, updated.

@mroeschke mroeschke added this to the 2.1 milestone Mar 9, 2023
@mroeschke mroeschke merged commit a53cf8d into pandas-dev:main Mar 9, 2023
@mroeschke
Copy link
Member

Thanks @lukemanley

@lukemanley lukemanley deleted the dataframe-stack-ea-dtypes branch March 17, 2023 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug ExtensionArray Extending pandas with custom dtypes or arrays. Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: stack_multi_columns extension array downcast
3 participants