Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
h-vetinari opened this issue Nov 7, 2018 · 1 comment

Comments

Projects
None yet
3 participants
@h-vetinari
Copy link
Contributor

commented Nov 7, 2018

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.

@gfyoung

This comment has been minimized.

Copy link
Member

commented Nov 8, 2018

Yikes! That's a pretty serious bug there...

cc @jreback

@gfyoung gfyoung added the Strings label Nov 8, 2018

@h-vetinari h-vetinari referenced this issue Nov 29, 2018

Merged

API: fix str-accessor on CategoricalIndex #24005

3 of 3 tasks complete

@jreback jreback added this to the 0.24.0 milestone Dec 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.