Skip to content

Conversation

skalwaghe-56
Copy link
Contributor

@skalwaghe-56 skalwaghe-56 commented Sep 5, 2025


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.

@skalwaghe-56
Copy link
Contributor Author

@jbrockmendel Please let me know if it needs any other changes.

@skalwaghe-56
Copy link
Contributor Author

@jbrockmendel Updated the documentation too! Let me know if this needs any other changes.

@skalwaghe-56 skalwaghe-56 force-pushed the fix-62244-unstack-bool-dtype-memory branch from 59565e6 to 95b4f5a Compare September 5, 2025 08:33
@jbrockmendel
Copy link
Member

jbrockmendel commented Sep 5, 2025

Nullable dtypes are opt-in. We don't silently cast to them. This issue will probably go un-resolved until PDEP16 is fully implemented.

@skalwaghe-56 skalwaghe-56 marked this pull request as draft September 6, 2025 07:05
- 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.
@skalwaghe-56 skalwaghe-56 force-pushed the fix-62244-unstack-bool-dtype-memory branch from 990800f to 98ac57d Compare September 6, 2025 07:05
@skalwaghe-56
Copy link
Contributor Author

@jbrockmendel What do you suggest we do? Close this PR or keep it open? Thank you for your guidance!

@jbrockmendel
Copy link
Member

Close it, yes.

@skalwaghe-56
Copy link
Contributor Author

@jbrockmendel Closing the PR. Thank you!

@skalwaghe-56 skalwaghe-56 deleted the fix-62244-unstack-bool-dtype-memory branch September 6, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PERF: DataFrame.unstack() and DataFrame.pivot_table() upcasting take up more memory than needed
2 participants