Skip to content

BUG: many methods on CategoricalIndex.str are broken #23556

Closed
@h-vetinari

Description

@h-vetinari

This was also uncovered by #23167, but is a different error than #23555.

Basically, all methods calling CategoricalIndex.str._wrap_result(result, use_codes=True) will necessarily fail, e.g.:

>>> import pandas as pd
>>> pd.Index(['a', 'b', 'aa'], dtype='category').str.replace('a', 'c')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Miniconda3\envs\pandas-dev\lib\site-packages\pandas\core\strings.py", line 2430, in replace
    return self._wrap_result(result)
  File "C:\ProgramData\Miniconda3\envs\pandas-dev\lib\site-packages\pandas\core\strings.py", line 1964, in _wrap_result
    result = take_1d(result, self._orig.cat.codes)
AttributeError: 'CategoricalIndex' object has no attribute 'cat'

This is because self._orig is the original CategoricalIndex, which does not have a cat-accessor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugCategoricalCategorical Data TypeIndexingRelated to indexing on series/frames, not to indexes themselvesStringsString extension data type and string data

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions