Skip to content

Commit 5157bd0

Browse files
committed
BUG: scalar getitem with a CI
1 parent d9a102c commit 5157bd0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

doc/source/whatsnew/v0.20.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,7 @@ Indexing
16291629
- Bug in the display of ``.info()`` where a qualifier (+) would always be displayed with a ``MultiIndex`` that contains only non-strings (:issue:`15245`)
16301630
- Bug in ``pd.concat()`` where the names of ``MultiIndex`` of resulting ``DataFrame`` are not handled correctly when ``None`` is presented in the names of ``MultiIndex`` of input ``DataFrame`` (:issue:`15787`)
16311631
- Bug in ``DataFrame.sort_index()`` and ``Series.sort_index()`` where ``na_position`` doesn't work with a ``MultiIndex`` (:issue:`14784`, :issue:`16604`)
1632+
- Bug in indexing with a scalar and a ``CategoricalIndex`` (:issue:`16123`)
16321633

16331634
I/O
16341635
^^^

pandas/core/indexes/category.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
is_list_like,
1111
is_interval_dtype,
1212
is_scalar)
13-
from pandas.core.common import _asarray_tuplesafe
13+
from pandas.core.common import (_asarray_tuplesafe,
14+
_values_from_object)
1415
from pandas.core.dtypes.missing import array_equivalent
1516

1617

@@ -352,6 +353,22 @@ def get_loc(self, key, method=None):
352353
raise KeyError(key)
353354
return self._engine.get_loc(codes)
354355

356+
def get_value(self, series, key):
357+
"""
358+
Fast lookup of value from 1-dimensional ndarray. Only use this if you
359+
know what you're doing
360+
"""
361+
try:
362+
k = _values_from_object(key)
363+
k = self._convert_scalar_indexer(k, kind='getitem')
364+
indexer = self.get_loc(k)
365+
return series.iloc[indexer]
366+
except KeyError:
367+
pass
368+
369+
# we might be a positional inexer
370+
return super(CategoricalIndex, self).get_value(series, key)
371+
355372
def _can_reindex(self, indexer):
356373
""" always allow reindexing """
357374
pass

0 commit comments

Comments
 (0)