diff --git a/pandas/core/indexes/frozen.py b/pandas/core/indexes/frozen.py index 3c6b922178abf..8bb65b0e8a7de 100644 --- a/pandas/core/indexes/frozen.py +++ b/pandas/core/indexes/frozen.py @@ -10,6 +10,7 @@ import numpy as np from pandas.core.base import PandasObject +from pandas.util._decorators import deprecate_kwarg from pandas.core.dtypes.cast import coerce_indexer_dtype from pandas.io.formats.printing import pprint_thing @@ -117,10 +118,9 @@ def __unicode__(self): quote_strings=True) return "%s(%s, dtype='%s')" % (type(self).__name__, prepr, self.dtype) - def searchsorted(self, v, side='left', sorter=None): + def searchsorted(self, value, side="left", sorter=None): """ - Find indices where elements of v should be inserted - in a to maintain order. + Find indices to insert `value` so as to maintain order. For full documentation, see `numpy.searchsorted` @@ -129,17 +129,20 @@ def searchsorted(self, v, side='left', sorter=None): numpy.searchsorted : equivalent function """ - # we are much more performant if the searched - # indexer is the same type as the array - # this doesn't matter for int64, but DOES + # We are much more performant if the searched + # indexer is the same type as the array. + # + # This doesn't matter for int64, but DOES # matter for smaller int dtypes - # https://github.com/numpy/numpy/issues/5370 + # + # xref: https://github.com/numpy/numpy/issues/5370 try: - v = self.dtype.type(v) + value = self.dtype.type(value) except: pass + return super(FrozenNDArray, self).searchsorted( - v, side=side, sorter=sorter) + value, side=side, sorter=sorter) def _ensure_frozen(array_like, categories, copy=False): diff --git a/pandas/tests/indexes/test_frozen.py b/pandas/tests/indexes/test_frozen.py index ca9841112b1d5..1fd16042098ea 100644 --- a/pandas/tests/indexes/test_frozen.py +++ b/pandas/tests/indexes/test_frozen.py @@ -69,3 +69,7 @@ def test_values(self): assert isinstance(self.container, FrozenNDArray) tm.assert_numpy_array_equal(self.container.values(), original) assert vals[0] == n + + def test_searchsorted(self): + expected = 2 + assert self.container.searchsorted(7) == expected