From e5d334f6592609eb02cbfee50cb0c231f84a07e3 Mon Sep 17 00:00:00 2001 From: gfyoung Date: Sat, 15 Sep 2018 10:53:41 -0700 Subject: [PATCH] DEPR: Standardize searchsorted signature (#22672) "value" is the law of the land. xref gh-14645. Follow-up to gh-15601. --- doc/source/whatsnew/v0.24.0.txt | 1 + pandas/core/indexes/frozen.py | 24 ++++++++++++++---------- pandas/tests/indexes/test_frozen.py | 7 +++++++ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index c7a28729df11f..649629714c3b1 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -560,6 +560,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 3c6b922178abf..5a37e03b700f9 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 - # matter for smaller int dtypes - # https://github.com/numpy/numpy/issues/5370 + # 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. + # + # 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..36d318e7a11aa 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