Skip to content
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: Fix bug in reindexing of period columns after unstack #61114

Merged
merged 1 commit into from
Mar 17, 2025

Conversation

snitish
Copy link
Contributor

@snitish snitish commented Mar 13, 2025

When indexing a Period block, the BaseBlockManager.reindex_indexer method thinks Period blocks can't store 2D values and always returns the first element. This is because it uses a hardcoded list of types (which is missing PeriodDtype) that are known to allow 2D values. The fix is to use the is_1d_only_ea_dtype utility function which internally uses the _supports_2d flag of the dtype.

The bug only happens when indexing a 2D period block, which may be created after operations like transpose, pivot, unstack etc.

@mroeschke mroeschke requested a review from jbrockmendel March 13, 2025 02:14
@mroeschke mroeschke added Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type labels Mar 13, 2025
Copy link
Member

@jbrockmendel jbrockmendel left a comment

Choose a reason for hiding this comment

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

LGTM

@mroeschke mroeschke added this to the 3.0 milestone Mar 17, 2025
@mroeschke mroeschke merged commit 71e6166 into pandas-dev:main Mar 17, 2025
48 checks passed
@mroeschke
Copy link
Member

Thanks @snitish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Indexing Related to indexing on series/frames, not to indexes themselves Period Period data type
Projects
None yet
3 participants