Skip to content

Commit e7e02e6

Browse files
committed
TST: platform indexing, xref GH8007
1 parent 489c394 commit e7e02e6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

pandas/core/categorical.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from pandas.core.indexing import _is_null_slice
1414
from pandas.tseries.period import PeriodIndex
1515
import pandas.core.common as com
16+
17+
from pandas.core.common import isnull
1618
from pandas.util.terminal import get_terminal_size
1719
from pandas.core.config import get_option
1820
from pandas.core import format as fmt
@@ -237,7 +239,7 @@ def __init__(self, values, levels=None, ordered=None, name=None, fastpath=False,
237239
# On list with NaNs, int values will be converted to float. Use "object" dtype
238240
# to prevent this. In the end objects will be casted to int/... in the level
239241
# assignment step.
240-
dtype = 'object' if com.isnull(values).any() else None
242+
dtype = 'object' if isnull(values).any() else None
241243
values = _sanitize_array(values, None, dtype=dtype)
242244

243245
if levels is None:
@@ -384,7 +386,7 @@ def _validate_levels(cls, levels):
384386
levels = _convert_to_list_like(levels)
385387
# on levels with NaNs, int values would be converted to float. Use "object" dtype
386388
# to prevent this.
387-
if com.isnull(levels).any():
389+
if isnull(levels).any():
388390
without_na = np.array([x for x in levels if com.notnull(x)])
389391
with_na = np.array(levels)
390392
if with_na.dtype != without_na.dtype:
@@ -513,9 +515,9 @@ def isnull(self):
513515
# String/object and float levels can hold np.nan
514516
if self.levels.dtype.kind in ['S', 'O', 'f']:
515517
if np.nan in self.levels:
516-
nan_pos = np.where(com.isnull(self.levels))
518+
nan_pos = np.where(isnull(self.levels))[0]
517519
# we only have one NA in levels
518-
ret = np.logical_or(ret , self._codes == nan_pos[0])
520+
ret = np.logical_or(ret , self._codes == nan_pos)
519521
return ret
520522

521523
def notnull(self):
@@ -714,9 +716,9 @@ def fillna(self, fill_value=None, method=None, limit=None, **kwargs):
714716
if self.levels.dtype.kind in ['S', 'O', 'f']:
715717
if np.nan in self.levels:
716718
values = values.copy()
717-
nan_pos = np.where(com.isnull(self.levels))
719+
nan_pos = np.where(isnull(self.levels))[0]
718720
# we only have one NA in levels
719-
values[values == nan_pos[0]] = -1
721+
values[values == nan_pos] = -1
720722

721723

722724
# pad / bfill
@@ -885,7 +887,7 @@ def __setitem__(self, key, value):
885887
rvalue = value if com.is_list_like(value) else [value]
886888
to_add = Index(rvalue)-self.levels
887889
# no assignments of values not in levels, but it's always ok to set something to np.nan
888-
if len(to_add) and not com.isnull(to_add).all():
890+
if len(to_add) and not isnull(to_add).all():
889891
raise ValueError("cannot setitem on a Categorical with a new level,"
890892
" set the levels first")
891893

@@ -924,8 +926,8 @@ def __setitem__(self, key, value):
924926
# is fixed.
925927
# float levels do currently return -1 for np.nan, even if np.nan is included in the index
926928
# "repair" this here
927-
if com.isnull(rvalue).any() and com.isnull(self.levels).any():
928-
nan_pos = np.where(com.isnull(self.levels))
929+
if isnull(rvalue).any() and isnull(self.levels).any():
930+
nan_pos = np.where(com.isnull(self.levels))[0]
929931
lindexer[lindexer == -1] = nan_pos
930932

931933
self._codes[key] = lindexer

0 commit comments

Comments
 (0)