Skip to content

Commit c39453a

Browse files
committed
add perf optimization in searchsorted for FrozenNDArray
1 parent 0e9c4a4 commit c39453a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pandas/indexes/frozen.py

+22
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,28 @@ 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):
121+
"""
122+
Find indices where elements of v should be inserted
123+
in a to maintain order.
124+
125+
For full documentation, see `numpy.searchsorted`
126+
127+
See Also
128+
--------
129+
numpy.searchsorted : equivalent function
130+
Type: method_descriptor
131+
"""
132+
133+
# we are much more performant if we have the same
134+
# type as the indexer
135+
try:
136+
v = self.dtype.type(v)
137+
except:
138+
pass
139+
return super(FrozenNDArray, self).searchsorted(
140+
v, side=side, sorter=sorter)
141+
120142

121143
def _ensure_frozen(array_like, categories, copy=False):
122144
array_like = coerce_indexer_dtype(array_like, categories)

0 commit comments

Comments
 (0)