Skip to content

Commit 032232c

Browse files
committed
BUG: scalar getitem with a CI
1 parent 06e264a commit 032232c

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

doc/source/whatsnew/v0.20.0.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,8 @@ Indexing
16301630
- Bug in the display of ``.info()`` where a qualifier (+) would always be displayed with a ``MultiIndex`` that contains only non-strings (:issue:`15245`)
16311631
- 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`)
16321632
- Bug in ``DataFrame.sort_index()`` and ``Series.sort_index()`` where ``na_position`` doesn't work with a ``MultiIndex`` (:issue:`14784`, :issue:`16604`)
1633-
- Bug in in ``pd.concat()`` when combining objects with a ``CategoricalIndex`` (:issue:`16111`)
1633+
- Bug in in ``pd.concat()`` when combining objects with a ``CategoricalIndex`` (:issue:`16111`)
1634+
- Bug in indexing with a scalar and a ``CategoricalIndex`` (:issue:`16123`)
16341635

16351636
I/O
16361637
^^^

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
from pandas.core.algorithms import take_1d
1617

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

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

0 commit comments

Comments
 (0)