|
13 | 13 | from pandas.core.indexing import _is_null_slice |
14 | 14 | from pandas.tseries.period import PeriodIndex |
15 | 15 | import pandas.core.common as com |
| 16 | + |
| 17 | +from pandas.core.common import isnull |
16 | 18 | from pandas.util.terminal import get_terminal_size |
17 | 19 | from pandas.core.config import get_option |
18 | 20 | from pandas.core import format as fmt |
@@ -237,7 +239,7 @@ def __init__(self, values, levels=None, ordered=None, name=None, fastpath=False, |
237 | 239 | # On list with NaNs, int values will be converted to float. Use "object" dtype |
238 | 240 | # to prevent this. In the end objects will be casted to int/... in the level |
239 | 241 | # assignment step. |
240 | | - dtype = 'object' if com.isnull(values).any() else None |
| 242 | + dtype = 'object' if isnull(values).any() else None |
241 | 243 | values = _sanitize_array(values, None, dtype=dtype) |
242 | 244 |
|
243 | 245 | if levels is None: |
@@ -384,7 +386,7 @@ def _validate_levels(cls, levels): |
384 | 386 | levels = _convert_to_list_like(levels) |
385 | 387 | # on levels with NaNs, int values would be converted to float. Use "object" dtype |
386 | 388 | # to prevent this. |
387 | | - if com.isnull(levels).any(): |
| 389 | + if isnull(levels).any(): |
388 | 390 | without_na = np.array([x for x in levels if com.notnull(x)]) |
389 | 391 | with_na = np.array(levels) |
390 | 392 | if with_na.dtype != without_na.dtype: |
@@ -513,9 +515,9 @@ def isnull(self): |
513 | 515 | # String/object and float levels can hold np.nan |
514 | 516 | if self.levels.dtype.kind in ['S', 'O', 'f']: |
515 | 517 | if np.nan in self.levels: |
516 | | - nan_pos = np.where(com.isnull(self.levels)) |
| 518 | + nan_pos = np.where(isnull(self.levels))[0] |
517 | 519 | # 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) |
519 | 521 | return ret |
520 | 522 |
|
521 | 523 | def notnull(self): |
@@ -714,9 +716,9 @@ def fillna(self, fill_value=None, method=None, limit=None, **kwargs): |
714 | 716 | if self.levels.dtype.kind in ['S', 'O', 'f']: |
715 | 717 | if np.nan in self.levels: |
716 | 718 | values = values.copy() |
717 | | - nan_pos = np.where(com.isnull(self.levels)) |
| 719 | + nan_pos = np.where(isnull(self.levels))[0] |
718 | 720 | # we only have one NA in levels |
719 | | - values[values == nan_pos[0]] = -1 |
| 721 | + values[values == nan_pos] = -1 |
720 | 722 |
|
721 | 723 |
|
722 | 724 | # pad / bfill |
@@ -885,7 +887,7 @@ def __setitem__(self, key, value): |
885 | 887 | rvalue = value if com.is_list_like(value) else [value] |
886 | 888 | to_add = Index(rvalue)-self.levels |
887 | 889 | # 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(): |
889 | 891 | raise ValueError("cannot setitem on a Categorical with a new level," |
890 | 892 | " set the levels first") |
891 | 893 |
|
@@ -924,8 +926,8 @@ def __setitem__(self, key, value): |
924 | 926 | # is fixed. |
925 | 927 | # float levels do currently return -1 for np.nan, even if np.nan is included in the index |
926 | 928 | # "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] |
929 | 931 | lindexer[lindexer == -1] = nan_pos |
930 | 932 |
|
931 | 933 | self._codes[key] = lindexer |
|
0 commit comments