Skip to content

ENH: Add union_categories parameter to pd.concat#65098

Open
jbrockmendel wants to merge 3 commits intopandas-dev:mainfrom
jbrockmendel:enh-concat-categorical
Open

ENH: Add union_categories parameter to pd.concat#65098
jbrockmendel wants to merge 3 commits intopandas-dev:mainfrom
jbrockmendel:enh-concat-categorical

Conversation

@jbrockmendel
Copy link
Copy Markdown
Member

@jbrockmendel jbrockmendel commented Apr 6, 2026

Summary

Test plan

  • Tests for Series with different/same categories
  • Tests for DataFrame with single and multiple categorical columns
  • Tests for mixed categorical/non-categorical (no effect)
  • Tests for ordered categoricals (compatible and incompatible)
  • Tests for integer and datetime categories
  • Test that default False preserves existing behavior

🤖 Generated with Claude Code

Add a `union_categories` keyword to `pd.concat` that preserves
categorical dtype by taking the union of categories when
concatenating Categoricals with different category sets.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jbrockmendel jbrockmendel marked this pull request as ready for review April 8, 2026 20:58
jbrockmendel and others added 2 commits April 8, 2026 13:58
Use already-imported CategoricalDtype for the isinstance check and
call _concat_same_type via the first element instead of importing
Categorical. Also clean up docstring to refer to dtype not class.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cast to Sequence[ExtensionArray] to satisfy mypy after the
CategoricalDtype isinstance check.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant