@@ -1035,11 +1035,13 @@ def is_lexsorted(self):
1035
1035
"""
1036
1036
return self .lexsort_depth == self .nlevels
1037
1037
1038
- def is_lexsorted_for_tuple (self , tup ):
1038
+ def _true_slices_indices (self , tup ):
1039
1039
"""
1040
- Return True if we are correctly lexsorted given the passed tuple
1040
+ Return indices of (non-trivial) slices in "tup"
1041
1041
"""
1042
- return len (tup ) <= self .lexsort_depth
1042
+ slices = lambda k : (isinstance (k , slice )
1043
+ and (k .start is not None or k .stop is not None ))
1044
+ return [(i if slices (k ) else - 1 ) for (i , k ) in enumerate (tup )]
1043
1045
1044
1046
@cache_readonly
1045
1047
def lexsort_depth (self ):
@@ -2262,12 +2264,12 @@ def get_locs(self, tup):
2262
2264
"""
2263
2265
2264
2266
# must be lexsorted to at least as many levels
2265
- if not self .is_lexsorted_for_tuple (tup ):
2267
+ last_slice = max (self ._true_slices_indices (tup ))
2268
+ if last_slice > self .lexsort_depth :
2266
2269
raise UnsortedIndexError ('MultiIndex Slicing requires the index '
2267
- 'to be fully lexsorted tuple len ({0}), '
2270
+ 'to be lexsorted: slicing on level ({0}), '
2268
2271
'lexsort depth ({1})'
2269
- .format (len (tup ), self .lexsort_depth ))
2270
-
2272
+ .format (last_slice , self .lexsort_depth ))
2271
2273
# indexer
2272
2274
# this is the list of all values that we want to select
2273
2275
n = len (self )
0 commit comments