-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Clarify is_bool_indexer for Extension dtypes #22326
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
Comments
Likewise for |
This manifests in failures for In [3]: pd.Series([1, 2, 3]).loc[pd.Categorical([True, False, True])]
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-3-0532517e2922> in <module>()
----> 1 pd.Series([1, 2, 3]).loc[pd.Categorical([True, False, True])]
~/sandbox/pandas/pandas/core/indexing.py in __getitem__(self, key)
1500
1501 maybe_callable = com.apply_if_callable(key, self.obj)
-> 1502 return self._getitem_axis(maybe_callable, axis=axis)
1503
1504 def _is_scalar_access(self, key):
~/sandbox/pandas/pandas/core/indexing.py in _getitem_axis(self, key, axis)
1902 raise ValueError('Cannot index with multidimensional key')
1903
-> 1904 return self._getitem_iterable(key, axis=axis)
1905
1906 # nested tuple slicing
~/sandbox/pandas/pandas/core/indexing.py in _getitem_iterable(self, key, axis)
1203 # A collection of keys
1204 keyarr, indexer = self._get_listlike_indexer(key, axis,
-> 1205 raise_missing=False)
1206 return self.obj._reindex_with_indexers({axis: [keyarr, indexer]},
1207 copy=True, allow_dups=True)
~/sandbox/pandas/pandas/core/indexing.py in _get_listlike_indexer(self, key, axis, raise_missing)
1159 self._validate_read_indexer(keyarr, indexer,
1160 o._get_axis_number(axis),
-> 1161 raise_missing=raise_missing)
1162 return keyarr, indexer
1163
~/sandbox/pandas/pandas/core/indexing.py in _validate_read_indexer(self, key, indexer, axis, raise_missing)
1244 raise KeyError(
1245 u"None of [{key}] are in the [{axis}]".format(
-> 1246 key=key, axis=self.obj._get_axis_name(axis)))
1247
1248 # We (temporarily) allow for some missing keys with .loc, except in
KeyError: "None of [Index([True, False, True], dtype='object')] are in the [index]" That should be |
Should we have something similar on the dtype as for numeric data? (the Because otherwise those inspection functions would need to know how to inspect the dtype (for categorical checking the dtype of the categories). I am only a bit worried about a possible proliferation of such attributes .. (now, categorical with boolean categories also doesn't sound that useful. We could also say we require an actual boolean dtype to do boolean indexing) |
I suppose this is what the Right now In [8]: pd.Categorical([True, False]).dtype.kind
Out[8]: 'O' If we changed that to be |
What do we want here?
working around this in #22325
The text was updated successfully, but these errors were encountered: