|
19 | 19 | from pandas.core.common import isnull, array_equivalent
|
20 | 20 | import pandas.core.common as com
|
21 | 21 | from pandas.core.common import (_values_from_object, is_float, is_integer,
|
22 |
| - ABCSeries, _ensure_object, _ensure_int64) |
| 22 | + ABCSeries, _ensure_object, _ensure_int64, is_bool_indexer, |
| 23 | + is_list_like, is_bool_dtype, is_integer_dtype) |
23 | 24 | from pandas.core.config import get_option
|
24 | 25 | from pandas.io.common import PerformanceWarning
|
25 | 26 |
|
@@ -55,7 +56,7 @@ def wrapper(self, other):
|
55 | 56 |
|
56 | 57 | # technically we could support bool dtyped Index
|
57 | 58 | # for now just return the indexing array directly
|
58 |
| - if com.is_bool_dtype(result): |
| 59 | + if is_bool_dtype(result): |
59 | 60 | return result
|
60 | 61 | try:
|
61 | 62 | return Index(result)
|
@@ -160,7 +161,7 @@ def __new__(cls, data=None, dtype=None, copy=False, name=None, fastpath=False,
|
160 | 161 | return Int64Index(data, copy=copy, dtype=dtype, name=name)
|
161 | 162 | elif issubclass(data.dtype.type, np.floating):
|
162 | 163 | return Float64Index(data, copy=copy, dtype=dtype, name=name)
|
163 |
| - elif issubclass(data.dtype.type, np.bool) or com.is_bool_dtype(data): |
| 164 | + elif issubclass(data.dtype.type, np.bool) or is_bool_dtype(data): |
164 | 165 | subarr = data.astype('object')
|
165 | 166 | else:
|
166 | 167 | subarr = com._asarray_tuplesafe(data, dtype=object)
|
@@ -510,15 +511,15 @@ def set_names(self, names, level=None, inplace=False):
|
510 | 511 | if level is not None and self.nlevels == 1:
|
511 | 512 | raise ValueError('Level must be None for non-MultiIndex')
|
512 | 513 |
|
513 |
| - if level is not None and not com.is_list_like(level) and com.is_list_like(names): |
| 514 | + if level is not None and not is_list_like(level) and is_list_like(names): |
514 | 515 | raise TypeError("Names must be a string")
|
515 | 516 |
|
516 |
| - if not com.is_list_like(names) and level is None and self.nlevels > 1: |
| 517 | + if not is_list_like(names) and level is None and self.nlevels > 1: |
517 | 518 | raise TypeError("Must pass list-like as `names`.")
|
518 | 519 |
|
519 |
| - if not com.is_list_like(names): |
| 520 | + if not is_list_like(names): |
520 | 521 | names = [names]
|
521 |
| - if level is not None and not com.is_list_like(level): |
| 522 | + if level is not None and not is_list_like(level): |
522 | 523 | level = [level]
|
523 | 524 |
|
524 | 525 | if inplace:
|
@@ -768,7 +769,7 @@ def _convert_list_indexer_for_mixed(self, keyarr, typ=None):
|
768 | 769 | and we have a mixed index (e.g. number/labels). figure out
|
769 | 770 | the indexer. return None if we can't help
|
770 | 771 | """
|
771 |
| - if (typ is None or typ in ['iloc','ix']) and (com.is_integer_dtype(keyarr) and not self.is_floating()): |
| 772 | + if (typ is None or typ in ['iloc','ix']) and (is_integer_dtype(keyarr) and not self.is_floating()): |
772 | 773 | if self.inferred_type != 'integer':
|
773 | 774 | keyarr = np.where(keyarr < 0,
|
774 | 775 | len(self) + keyarr, keyarr)
|
@@ -929,7 +930,7 @@ def __getitem__(self, key):
|
929 | 930 | # pessimization of basic indexing.
|
930 | 931 | return promote(getitem(key))
|
931 | 932 |
|
932 |
| - if com._is_bool_indexer(key): |
| 933 | + if is_bool_indexer(key): |
933 | 934 | key = np.asarray(key)
|
934 | 935 |
|
935 | 936 | key = _values_from_object(key)
|
@@ -2104,7 +2105,7 @@ def get_slice_bound(self, label, side):
|
2104 | 2105 | if isinstance(slc, np.ndarray):
|
2105 | 2106 | # get_loc may return a boolean array or an array of indices, which
|
2106 | 2107 | # is OK as long as they are representable by a slice.
|
2107 |
| - if com.is_bool_dtype(slc): |
| 2108 | + if is_bool_dtype(slc): |
2108 | 2109 | slc = lib.maybe_booleans_to_slice(slc.view('u1'))
|
2109 | 2110 | else:
|
2110 | 2111 | slc = lib.maybe_indices_to_slice(slc.astype('i8'))
|
@@ -2882,15 +2883,15 @@ def set_levels(self, levels, level=None, inplace=False, verify_integrity=True):
|
2882 | 2883 | labels=[[0, 0, 1, 1], [0, 1, 0, 1]],
|
2883 | 2884 | names=[u'foo', u'bar'])
|
2884 | 2885 | """
|
2885 |
| - if level is not None and not com.is_list_like(level): |
2886 |
| - if not com.is_list_like(levels): |
| 2886 | + if level is not None and not is_list_like(level): |
| 2887 | + if not is_list_like(levels): |
2887 | 2888 | raise TypeError("Levels must be list-like")
|
2888 |
| - if com.is_list_like(levels[0]): |
| 2889 | + if is_list_like(levels[0]): |
2889 | 2890 | raise TypeError("Levels must be list-like")
|
2890 | 2891 | level = [level]
|
2891 | 2892 | levels = [levels]
|
2892 |
| - elif level is None or com.is_list_like(level): |
2893 |
| - if not com.is_list_like(levels) or not com.is_list_like(levels[0]): |
| 2893 | + elif level is None or is_list_like(level): |
| 2894 | + if not is_list_like(levels) or not is_list_like(levels[0]): |
2894 | 2895 | raise TypeError("Levels must be list of lists-like")
|
2895 | 2896 |
|
2896 | 2897 | if inplace:
|
@@ -2980,15 +2981,15 @@ def set_labels(self, labels, level=None, inplace=False, verify_integrity=True):
|
2980 | 2981 | labels=[[1, 0, 1, 0], [0, 0, 1, 1]],
|
2981 | 2982 | names=[u'foo', u'bar'])
|
2982 | 2983 | """
|
2983 |
| - if level is not None and not com.is_list_like(level): |
2984 |
| - if not com.is_list_like(labels): |
| 2984 | + if level is not None and not is_list_like(level): |
| 2985 | + if not is_list_like(labels): |
2985 | 2986 | raise TypeError("Labels must be list-like")
|
2986 |
| - if com.is_list_like(labels[0]): |
| 2987 | + if is_list_like(labels[0]): |
2987 | 2988 | raise TypeError("Labels must be list-like")
|
2988 | 2989 | level = [level]
|
2989 | 2990 | labels = [labels]
|
2990 |
| - elif level is None or com.is_list_like(level): |
2991 |
| - if not com.is_list_like(labels) or not com.is_list_like(labels[0]): |
| 2991 | + elif level is None or is_list_like(level): |
| 2992 | + if not is_list_like(labels) or not is_list_like(labels[0]): |
2992 | 2993 | raise TypeError("Labels must be list of lists-like")
|
2993 | 2994 |
|
2994 | 2995 | if inplace:
|
@@ -3642,7 +3643,7 @@ def __getitem__(self, key):
|
3642 | 3643 |
|
3643 | 3644 | return tuple(retval)
|
3644 | 3645 | else:
|
3645 |
| - if com._is_bool_indexer(key): |
| 3646 | + if is_bool_indexer(key): |
3646 | 3647 | key = np.asarray(key)
|
3647 | 3648 | sortorder = self.sortorder
|
3648 | 3649 | else:
|
@@ -4404,14 +4405,14 @@ def _convert_indexer(r):
|
4404 | 4405 | ranges = []
|
4405 | 4406 | for i,k in enumerate(tup):
|
4406 | 4407 |
|
4407 |
| - if com._is_bool_indexer(k): |
| 4408 | + if is_bool_indexer(k): |
4408 | 4409 | # a boolean indexer, must be the same length!
|
4409 | 4410 | k = np.asarray(k)
|
4410 | 4411 | if len(k) != len(self):
|
4411 | 4412 | raise ValueError("cannot index with a boolean indexer that is"
|
4412 | 4413 | " not the same length as the index")
|
4413 | 4414 | ranges.append(k)
|
4414 |
| - elif com.is_list_like(k): |
| 4415 | + elif is_list_like(k): |
4415 | 4416 | # a collection of labels to include from this level (these are or'd)
|
4416 | 4417 | indexers = []
|
4417 | 4418 | for x in k:
|
|
0 commit comments