Skip to content

Commit 574d366

Browse files
committed
DEPR: Standardize searchsorted signature
"values" is the law of the land. xref pandas-devgh-14645.
1 parent 73dd6ec commit 574d366

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

doc/source/whatsnew/v0.24.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ Deprecations
557557
- :func:`pandas.read_table` is deprecated. Instead, use :func:`pandas.read_csv` passing ``sep='\t'`` if necessary (:issue:`21948`)
558558
- :meth:`Series.str.cat` has deprecated using arbitrary list-likes *within* list-likes. A list-like container may still contain
559559
many ``Series``, ``Index`` or 1-dimensional ``np.ndarray``, or alternatively, only scalar values. (:issue:`21950`)
560+
- :meth:`FrozenNDArray.searchsorted` has deprecated the ``v`` parameter in favor of ``value`` (:issue:`14645`)
560561

561562
.. _whatsnew_0240.prior_deprecations:
562563

pandas/core/indexes/frozen.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import numpy as np
1212
from pandas.core.base import PandasObject
13+
from pandas.util._decorators import deprecate_kwarg
1314
from pandas.core.dtypes.cast import coerce_indexer_dtype
1415
from pandas.io.formats.printing import pprint_thing
1516

@@ -117,10 +118,10 @@ def __unicode__(self):
117118
quote_strings=True)
118119
return "%s(%s, dtype='%s')" % (type(self).__name__, prepr, self.dtype)
119120

120-
def searchsorted(self, v, side='left', sorter=None):
121+
@deprecate_kwarg(old_arg_name="v", new_arg_name="value")
122+
def searchsorted(self, value, side="left", sorter=None):
121123
"""
122-
Find indices where elements of v should be inserted
123-
in a to maintain order.
124+
Find indices to insert `value` so as to maintain order.
124125
125126
For full documentation, see `numpy.searchsorted`
126127
@@ -129,17 +130,20 @@ def searchsorted(self, v, side='left', sorter=None):
129130
numpy.searchsorted : equivalent function
130131
"""
131132

132-
# we are much more performant if the searched
133-
# indexer is the same type as the array
134-
# this doesn't matter for int64, but DOES
133+
# We are much more performant if the searched
134+
# indexer is the same type as the array.
135+
#
136+
# This doesn't matter for int64, but DOES
135137
# matter for smaller int dtypes
136-
# https://github.com/numpy/numpy/issues/5370
138+
#
139+
# xref: https://github.com/numpy/numpy/issues/5370
137140
try:
138-
v = self.dtype.type(v)
141+
value = self.dtype.type(value)
139142
except:
140143
pass
144+
141145
return super(FrozenNDArray, self).searchsorted(
142-
v, side=side, sorter=sorter)
146+
value, side=side, sorter=sorter)
143147

144148

145149
def _ensure_frozen(array_like, categories, copy=False):

pandas/tests/indexes/test_frozen.py

+7
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,10 @@ def test_values(self):
6969
assert isinstance(self.container, FrozenNDArray)
7070
tm.assert_numpy_array_equal(self.container.values(), original)
7171
assert vals[0] == n
72+
73+
def test_searchsorted(self):
74+
expected = 2
75+
assert self.container.searchsorted(7) == expected
76+
77+
with tm.assert_produces_warning(FutureWarning):
78+
assert self.container.searchsorted(v=7) == expected

0 commit comments

Comments
 (0)