Skip to content

BUG: concat with categorical keys doesn't preserve categorical dtype #14016

Open
@pijucha

Description

@pijucha

This is a follow-up issue to #13854.

Code Sample, a copy-pastable example if possible

cidx = pd.CategoricalIndex(['y', 'x'], categories=list("xyz"), ordered=True)
df = pd.DataFrame([[10, 11, 12]])

pd.concat([df, df], keys=cidx).index.levels[0]
Out[32]: Index(['y', 'x'], dtype='object')

Expected Output

CategoricalIndex(['y', 'x'], categories=['x', 'y', 'z'], ordered=True, dtype='category')

I decided to put it separately because a fix requires more changes than just a factorization introduced in #13854.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugCategoricalCategorical Data TypeReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions