-
-
Notifications
You must be signed in to change notification settings - Fork 19k
ENH: Preserve nullable boolean dtype in pivot_table (GH#62244) #62256
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
ENH: Preserve nullable boolean dtype in pivot_table (GH#62244) #62256
Conversation
@jbrockmendel Please let me know if it needs any other changes.
@jbrockmendel Updated the documentation too! Let me know if this needs any other changes.
59565e6
to
95b4f5a
Compare
Nullable dtypes are opt-in. We don't silently cast to them. This issue will probably go un-resolved until PDEP16 is fully implemented.
- Convert bool/object columns to BooleanDtype - Skip dtype conversion for margin columns that are DataFrames - Updated test_pivot_table_bool_preserves_boolean_dtype with safe assertions
- Added release note to v3.0.0.rst under Enhancements and Bug fixes, describing that boolean columns are now preserved as nullable BooleanDtype in pivoting and unstacking operations, with missing values as pd.NA. - References issue pandas-dev#62244.
990800f
to
98ac57d
Compare
@jbrockmendel What do you suggest we do? Close this PR or keep it open? Thank you for your guidance!
Close it, yes.
@jbrockmendel Closing the PR. Thank you!
Uh oh!
There was an error while loading. Please reload this page.
Convert bool/object columns to BooleanDtype
Skip dtype conversion for margin columns that are DataFrames
Updated test_pivot_table_bool_preserves_boolean_dtype with safe assertions
closes PERF:
DataFrame.unstack()
andDataFrame.pivot_table()
upcasting take up more memory than needed #62244Tests added and passed if fixing a bug or adding a new feature
All code checks passed.
Added an entry in the latest
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.ENH: Preserve nullable boolean dtype in pivot_table (GH#62244)
This PR ensures pivot_table preserves nullable boolean dtype instead of upcasting to float
for boolean columns or object columns containing only booleans. It also skips dtype conversion
for margin columns that are returned as DataFrames.
Includes updated test_pivot_table_bool_preserves_boolean_dtype with safe assertions
(assert / assert not) to comply with linting rules.