Skip to content

BUG: Categorical.map() errors when mapping categories to tuples#65841

Open
SharadhNaidu wants to merge 5 commits into
pandas-dev:mainfrom
SharadhNaidu:fix-categorical-map-tuple
Open

BUG: Categorical.map() errors when mapping categories to tuples#65841
SharadhNaidu wants to merge 5 commits into
pandas-dev:mainfrom
SharadhNaidu:fix-categorical-map-tuple

Conversation

@SharadhNaidu

@SharadhNaidu SharadhNaidu commented Jun 10, 2026

Copy link
Copy Markdown

Closes #51488

Categorical.map() (and by extension Series.map() on a categorical
Series) raised a NotImplementedError when the mapper produced tuple
values for the categories. Mapping the categories through Index.map()
returns a MultiIndex for tuple results, and a CategoricalDtype/
Categorical can't be built from a MultiIndex.

Detect that case and fall back to a flat object-dtype Index of tuples
(via to_flat_index()), matching how Index.map() already behaves when
a mapper returns tuples - so a categorical Series and a regular Series
now behave consistently here.

  • closes BUG: categorical Series.map() errors when mapping to tuples. #51488
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.
  • I have reviewed and followed all the contribution guidelines
  • If I used AI to develop this pull request, I prompted it to follow AGENTS.md.

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.

BUG: categorical Series.map() errors when mapping to tuples.

1 participant