Skip to content

Commit f309594

Browse files
committed
MAINT: Standardize searchsorted signature
"values" is the law of the land. This usage is internal, hence why we aren't going through a deprecation cycle. xref pandas-devgh-14645. Follow-up to pandas-devgh-15601.
1 parent 0473aab commit f309594

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

pandas/core/indexes/frozen.py

+12-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,9 @@ 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+
def searchsorted(self, value, side="left", sorter=None):
121122
"""
122-
Find indices where elements of v should be inserted
123-
in a to maintain order.
123+
Find indices to insert `value` so as to maintain order.
124124
125125
For full documentation, see `numpy.searchsorted`
126126
@@ -129,17 +129,20 @@ def searchsorted(self, v, side='left', sorter=None):
129129
numpy.searchsorted : equivalent function
130130
"""
131131

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
132+
# We are much more performant if the searched
133+
# indexer is the same type as the array.
134+
#
135+
# This doesn't matter for int64, but DOES
135136
# matter for smaller int dtypes
136-
# https://github.com/numpy/numpy/issues/5370
137+
#
138+
# xref: https://github.com/numpy/numpy/issues/5370
137139
try:
138-
v = self.dtype.type(v)
140+
value = self.dtype.type(value)
139141
except:
140142
pass
143+
141144
return super(FrozenNDArray, self).searchsorted(
142-
v, side=side, sorter=sorter)
145+
value, side=side, sorter=sorter)
143146

144147

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

pandas/tests/indexes/test_frozen.py

+4
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@ 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

0 commit comments

Comments
 (0)