-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
API: fix str-accessor on CategoricalIndex #24005
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
Changes from 2 commits
98ff497
2ea6fc0
b5f294c
1ee5dea
968e188
ecd08b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
from pandas.core.dtypes.common import ( | ||
ensure_object, is_bool_dtype, is_categorical_dtype, is_integer, | ||
is_list_like, is_object_dtype, is_re, is_scalar, is_string_like) | ||
from pandas.core.dtypes.generic import ABCIndex, ABCSeries | ||
from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries | ||
from pandas.core.dtypes.missing import isna | ||
|
||
from pandas.core.algorithms import take_1d | ||
|
@@ -931,7 +931,7 @@ def str_extractall(arr, pat, flags=0): | |
if regex.groups == 0: | ||
raise ValueError("pattern contains no capture groups") | ||
|
||
if isinstance(arr, ABCIndex): | ||
if isinstance(arr, ABCIndexClass): | ||
arr = arr.to_series().reset_index(drop=True) | ||
|
||
names = dict(zip(regex.groupindex.values(), regex.groupindex.keys())) | ||
|
@@ -1854,15 +1854,16 @@ def __iter__(self): | |
def _wrap_result(self, result, use_codes=True, | ||
name=None, expand=None, fill_value=np.nan): | ||
|
||
from pandas.core.index import Index, MultiIndex | ||
from pandas import Index, Series, MultiIndex | ||
|
||
# for category, we do the stuff on the categories, so blow it up | ||
# to the full series again | ||
# But for some operations, we have to do the stuff on the full values, | ||
# so make it possible to skip this step as the method already did this | ||
# before the transformation... | ||
if use_codes and self._is_categorical: | ||
result = take_1d(result, self._orig.cat.codes, | ||
# if self._orig is a CategoricalIndex, there is no .cat-accessor | ||
result = take_1d(result, Series(self._orig).cat.codes, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use |
||
fill_value=fill_value) | ||
|
||
if not hasattr(result, 'ndim') or not hasattr(result, 'dtype'): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,9 +245,6 @@ def test_api_per_method(self, box, dtype, | |
and inferred_dtype in ['boolean', 'date', 'time']): | ||
pytest.xfail(reason='Inferring incorrectly because of NaNs; ' | ||
'solved by GH 23167') | ||
if box == Index and dtype == 'category': | ||
pytest.xfail(reason='Broken methods on CategoricalIndex; ' | ||
'see GH 23556') | ||
|
||
t = box(values, dtype=dtype) # explicit dtype to avoid casting | ||
method = getattr(t.str, method_name) | ||
|
@@ -264,6 +261,7 @@ def test_api_per_method(self, box, dtype, | |
+ ['mixed', 'mixed-integer'] * mixed_allowed) | ||
|
||
if inferred_dtype in allowed_types: | ||
# inter alia GH 23555, GH 23556 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just say xref There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this one |
||
method(*args, **kwargs) # works! | ||
else: | ||
# GH 23011, GH 23163 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use double backticks