-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
API: generalized check_array_indexer for validating array-like getitem indexers #31150
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 8 commits
e8f539a
4fa9f5a
b55dfd2
095b741
58bfe78
5ce8d85
ebc2150
4a51d97
50490aa
c979df8
ce2e042
4d447bf
d930e84
9ed8fe9
2f8cd27
4d9a201
097d221
3c5e4c6
1ca35d1
e5ea9b4
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 |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ | |
| ) | ||
| from pandas.core.dtypes.dtypes import CategoricalDtype | ||
| from pandas.core.dtypes.generic import ABCIndexClass, ABCSeries | ||
| from pandas.core.dtypes.inference import is_array_like, is_hashable | ||
| from pandas.core.dtypes.inference import is_hashable | ||
| from pandas.core.dtypes.missing import isna, notna | ||
|
|
||
| from pandas.core import ops | ||
|
|
@@ -54,7 +54,7 @@ | |
| from pandas.core.base import NoNewAttributesMixin, PandasObject, _shared_docs | ||
| import pandas.core.common as com | ||
| from pandas.core.construction import array, extract_array, sanitize_array | ||
| from pandas.core.indexers import check_bool_array_indexer | ||
| from pandas.core.indexers import check_array_indexer | ||
| from pandas.core.missing import interpolate_2d | ||
| from pandas.core.ops.common import unpack_zerodim_and_defer | ||
| from pandas.core.sorting import nargsort | ||
|
|
@@ -2001,14 +2001,14 @@ def __getitem__(self, key): | |
| else: | ||
| return self.categories[i] | ||
|
|
||
| if is_list_like(key) and not is_array_like(key): | ||
| key = np.asarray(key) | ||
|
|
||
| if com.is_bool_indexer(key): | ||
| key = check_bool_array_indexer(self, key) | ||
| if is_list_like(key) and not isinstance(key, tuple): | ||
| key = check_array_indexer(self, key) | ||
|
|
||
| result = self._codes[key] | ||
| if result.ndim > 1: | ||
| from pandas.core.indexes.base import deprecate_ndim_indexing | ||
|
||
|
|
||
| deprecate_ndim_indexing(result) | ||
| return result | ||
| return self._constructor(result, dtype=self.dtype, fastpath=True) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ | |
| from pandas.core.algorithms import checked_add_with_arr, take, unique1d, value_counts | ||
| from pandas.core.arrays.base import ExtensionArray, ExtensionOpsMixin | ||
| import pandas.core.common as com | ||
| from pandas.core.indexers import check_bool_array_indexer | ||
| from pandas.core.indexers import check_array_indexer | ||
| from pandas.core.ops.common import unpack_zerodim_and_defer | ||
| from pandas.core.ops.invalid import invalid_comparison, make_invalid_op | ||
|
|
||
|
|
@@ -517,8 +517,12 @@ def __getitem__(self, key): | |
| return self._box_func(val) | ||
| return type(self)(val, dtype=self.dtype) | ||
|
|
||
| if is_list_like(key) and not isinstance(key, tuple): | ||
| key = check_array_indexer(self, key) | ||
|
|
||
jreback marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if com.is_bool_indexer(key): | ||
| key = check_bool_array_indexer(self, key) | ||
| # can still have object dtype | ||
|
||
| key = np.asarray(key, dtype=bool) | ||
| if key.all(): | ||
| key = slice(0, None, None) | ||
| else: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |
| is_datetime64_any_dtype, | ||
| is_dtype_equal, | ||
| is_integer, | ||
| is_list_like, | ||
| is_object_dtype, | ||
| is_scalar, | ||
| is_string_dtype, | ||
|
|
@@ -43,6 +44,7 @@ | |
| from pandas.core.base import PandasObject | ||
| import pandas.core.common as com | ||
| from pandas.core.construction import sanitize_array | ||
| from pandas.core.indexers import check_array_indexer | ||
| from pandas.core.missing import interpolate_2d | ||
| import pandas.core.ops as ops | ||
| from pandas.core.ops.common import unpack_zerodim_and_defer | ||
|
|
@@ -768,6 +770,9 @@ def __getitem__(self, key): | |
| else: | ||
| key = np.asarray(key) | ||
|
|
||
| if is_list_like(key): | ||
|
||
| key = check_array_indexer(self, key) | ||
|
|
||
| if com.is_bool_indexer(key): | ||
| key = check_bool_indexer(self, key) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ | |
|
|
||
| import pandas.core.common as com | ||
| from pandas.core.indexers import ( | ||
| check_bool_array_indexer, | ||
| check_array_indexer, | ||
| is_list_like_indexer, | ||
| length_of_indexer, | ||
| ) | ||
|
|
@@ -2232,7 +2232,7 @@ def check_bool_indexer(index: Index, key) -> np.ndarray: | |
| else: | ||
| if is_sparse(result): | ||
| result = result.to_dense() | ||
| result = check_bool_array_indexer(index, result) | ||
| result = np.asarray(check_array_indexer(index, result), dtype=bool) | ||
|
||
|
|
||
| return result | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.