Skip to content

Commit 4e9e8bc

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 ba2720b commit 4e9e8bc

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

pandas/core/indexes/frozen.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,9 @@ def __unicode__(self):
117117
quote_strings=True)
118118
return "%s(%s, dtype='%s')" % (type(self).__name__, prepr, self.dtype)
119119

120-
def searchsorted(self, v, side='left', sorter=None):
120+
def searchsorted(self, value, side="left", sorter=None):
121121
"""
122-
Find indices where elements of v should be inserted
123-
in a to maintain order.
122+
Find indices to insert `value` so as to maintain order.
124123
125124
For full documentation, see `numpy.searchsorted`
126125
@@ -129,17 +128,20 @@ def searchsorted(self, v, side='left', sorter=None):
129128
numpy.searchsorted : equivalent function
130129
"""
131130

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
131+
# We are much more performant if the searched
132+
# indexer is the same type as the array.
133+
#
134+
# This doesn't matter for int64, but DOES
135135
# matter for smaller int dtypes
136-
# https://github.com/numpy/numpy/issues/5370
136+
#
137+
# xref: https://github.com/numpy/numpy/issues/5370
137138
try:
138-
v = self.dtype.type(v)
139+
value = self.dtype.type(value)
139140
except:
140141
pass
142+
141143
return super(FrozenNDArray, self).searchsorted(
142-
v, side=side, sorter=sorter)
144+
value, side=side, sorter=sorter)
143145

144146

145147
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)