diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 3660c1e843f6cf..d001473bb533a6 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -557,6 +557,7 @@ Deprecations - :func:`pandas.read_table` is deprecated. Instead, use :func:`pandas.read_csv` passing ``sep='\t'`` if necessary (:issue:`21948`) - :meth:`Series.str.cat` has deprecated using arbitrary list-likes *within* list-likes. A list-like container may still contain many ``Series``, ``Index`` or 1-dimensional ``np.ndarray``, or alternatively, only scalar values. (:issue:`21950`) +- :meth:`FrozenNDArray.searchsorted` has deprecated the ``v`` parameter in favor of ``value`` (:issue:`14645`) .. _whatsnew_0240.prior_deprecations: diff --git a/pandas/core/indexes/frozen.py b/pandas/core/indexes/frozen.py index 3c6b922178abf3..4c92bb29c1afda 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,10 @@ 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): + @deprecate_kwarg(old_arg_name="v", new_arg_name="value") + 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 +130,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 ca9841112b1d57..36d318e7a11aac 100644 --- a/pandas/tests/indexes/test_frozen.py +++ b/pandas/tests/indexes/test_frozen.py @@ -69,3 +69,10 @@ 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 + + with tm.assert_produces_warning(FutureWarning): + assert self.container.searchsorted(v=7) == expected