Skip to content

BUG: union_categoricals w/Series & CategoricalIndex #14173

Closed
@jreback

Description

@jreback
In [25]: from pandas.types.concat import union_categoricals

In [26]: s1 = pd.Series(['a', 'b'], dtype='category')
    ...: s3 = pd.Series(['a', 'b', 'c'], dtype='category')

In [27]: s1
Out[27]: 
0    a
1    b
dtype: category
Categories (2, object): [a, b]

In [28]: s3
Out[28]: 
0    a
1    b
2    c
dtype: category
Categories (3, object): [a, b, c]

I don't see why this shouldn't work. This should return a Categorical.

In [29]: union_categoricals([s1,s3])
AttributeError: 'Series' object has no attribute 'categories'

actual categoricals are combinable

In [30]: union_categoricals([s1.values,s3.values])
Out[30]: 
[a, b, a, b, c]
Categories (3, object): [a, b, c]

This works fine

In [31]: union_categoricals([s1.values,pd.CategoricalIndex(s3.values)])
Out[31]: 
[a, b, a, b, c]
Categories (3, object): [a, b, c]

But this is broken

In [32]: union_categoricals([pd.CategoricalIndex(s1.values),pd.CategoricalIndex(s3.values)])
AttributeError: 'CategoricalIndex' object has no attribute 'is_dtype_equal'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions