@@ -435,23 +435,27 @@ def _convert_to_indexer(self, obj, axis=0):
435
435
if isinstance (obj , slice ):
436
436
ltype = labels .inferred_type
437
437
438
- if ltype == 'floating' :
439
- int_slice = _is_int_slice (obj )
440
- else :
441
- # floats that are within tolerance of int used
442
- int_slice = _is_index_slice (obj )
438
+ # in case of providing all floats, use label-based indexing
439
+ float_slice = (labels .inferred_type == 'floating'
440
+ and _is_float_slice (obj ))
441
+
442
+ # floats that are within tolerance of int used as positions
443
+ int_slice = _is_index_slice (obj )
443
444
444
445
null_slice = obj .start is None and obj .stop is None
445
- # could have integers in the first level of the MultiIndex
446
+
447
+ # could have integers in the first level of the MultiIndex,
448
+ # in which case we wouldn't want to do position-based slicing
446
449
position_slice = (int_slice
447
450
and not ltype == 'integer'
448
- and not isinstance (labels , MultiIndex ))
451
+ and not isinstance (labels , MultiIndex )
452
+ and not float_slice )
449
453
450
454
start , stop = obj .start , obj .stop
451
455
452
456
# last ditch effort: if we are mixed and have integers
453
457
try :
454
- if 'mixed' in ltype and int_slice :
458
+ if position_slice and 'mixed' in ltype :
455
459
if start is not None :
456
460
i = labels .get_loc (start )
457
461
if stop is not None :
@@ -468,7 +472,7 @@ def _convert_to_indexer(self, obj, axis=0):
468
472
indexer = labels .slice_indexer (start , stop , obj .step )
469
473
except Exception :
470
474
if _is_index_slice (obj ):
471
- if labels . inferred_type == 'integer' :
475
+ if ltype == 'integer' :
472
476
raise
473
477
indexer = obj
474
478
else :
@@ -539,34 +543,36 @@ def _get_slice_axis(self, slice_obj, axis=0):
539
543
540
544
labels = obj ._get_axis (axis )
541
545
542
- int_slice = _is_index_slice (slice_obj )
543
-
544
- start = slice_obj .start
545
- stop = slice_obj .stop
546
+ ltype = labels .inferred_type
546
547
547
548
# in case of providing all floats, use label-based indexing
548
549
float_slice = (labels .inferred_type == 'floating'
549
550
and _is_float_slice (slice_obj ))
550
551
552
+ # floats that are within tolerance of int used as positions
553
+ int_slice = _is_index_slice (slice_obj )
554
+
551
555
null_slice = slice_obj .start is None and slice_obj .stop is None
552
556
553
- # could have integers in the first level of the MultiIndex, in which
554
- # case we wouldn't want to do position-based slicing
557
+ # could have integers in the first level of the MultiIndex,
558
+ # in which case we wouldn't want to do position-based slicing
555
559
position_slice = (int_slice
556
- and labels . inferred_type ! = 'integer'
560
+ and not ltype = = 'integer'
557
561
and not isinstance (labels , MultiIndex )
558
562
and not float_slice )
559
563
564
+ start , stop = slice_obj .start , slice_obj .stop
565
+
560
566
# last ditch effort: if we are mixed and have integers
561
567
try :
562
- if 'mixed' in labels . inferred_type and int_slice :
568
+ if position_slice and 'mixed' in ltype :
563
569
if start is not None :
564
570
i = labels .get_loc (start )
565
571
if stop is not None :
566
572
j = labels .get_loc (stop )
567
573
position_slice = False
568
574
except KeyError :
569
- if labels . inferred_type == 'mixed-integer-float' :
575
+ if ltype == 'mixed-integer-float' :
570
576
raise
571
577
572
578
if null_slice or position_slice :
@@ -576,7 +582,7 @@ def _get_slice_axis(self, slice_obj, axis=0):
576
582
indexer = labels .slice_indexer (start , stop , slice_obj .step )
577
583
except Exception :
578
584
if _is_index_slice (slice_obj ):
579
- if labels . inferred_type == 'integer' :
585
+ if ltype == 'integer' :
580
586
raise
581
587
indexer = slice_obj
582
588
else :
0 commit comments