Skip to content

Commit 4251f99

Browse files
committed
implement searchsorted for multindex (bug pandas-dev#14833)
1 parent 9285820 commit 4251f99

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/core/indexes/multi.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,6 +2899,12 @@ def isin(self, values, level=None):
28992899
else:
29002900
return np.lib.arraysetops.in1d(labs, sought_labels)
29012901

2902+
def searchsorted(self, arr):
2903+
from functools import reduce
2904+
dtype = reduce(lambda x, y : x + y, [l.dtype.descr for l in self.levels], [])
2905+
return self.values.astype(dtype).searchsorted(np.asarray(arr, dtype=dtype))
2906+
2907+
29022908

29032909
MultiIndex._add_numeric_methods_disabled()
29042910
MultiIndex._add_numeric_methods_add_sub_disabled()
@@ -2933,5 +2939,6 @@ def _sparsify(label_list, start=0, sentinel=''):
29332939
return lzip(*result)
29342940

29352941

2942+
29362943
def _get_na_rep(dtype):
29372944
return {np.datetime64: 'NaT', np.timedelta64: 'NaT'}.get(dtype, 'NaN')

0 commit comments

Comments
 (0)