@@ -371,8 +371,9 @@ def slice_locs_cases(self, breaks):
371371 assert index .slice_locs (1 , 1 ) == (1 , 1 )
372372 assert index .slice_locs (1 , 2 ) == (1 , 2 )
373373
374- index = IntervalIndex .from_breaks ([0 , 1 , 2 ], closed = 'both' )
375- assert index .slice_locs (1 , 1 ) == (0 , 2 )
374+ index = IntervalIndex .from_tuples ([(0 , 1 ), (2 , 3 ), (4 , 5 )],
375+ closed = 'both' )
376+ assert index .slice_locs (1 , 1 ) == (0 , 1 )
376377 assert index .slice_locs (1 , 2 ) == (0 , 2 )
377378
378379 def test_slice_locs_int64 (self ):
@@ -681,6 +682,47 @@ def f():
681682
682683 pytest .raises (ValueError , f )
683684
685+ def test_is_non_overlapping_monotonic (self ):
686+ # Verify that a Python Boolean is returned (GH17237)
687+ for closed in ('left' , 'right' , 'neither' , 'both' ):
688+ idx = IntervalIndex .from_breaks (range (4 ), closed = closed )
689+ assert type (idx .is_non_overlapping_monotonic ) is bool
690+
691+ # Should be True in all cases
692+ tpls = [(0 , 1 ), (2 , 3 ), (4 , 5 ), (6 , 7 )]
693+ for closed in ('left' , 'right' , 'neither' , 'both' ):
694+ idx = IntervalIndex .from_tuples (tpls , closed = closed )
695+ assert idx .is_non_overlapping_monotonic is True
696+
697+ idx = IntervalIndex .from_tuples (reversed (tpls ), closed = closed )
698+ assert idx .is_non_overlapping_monotonic is True
699+
700+ # Should be False in all cases (overlapping)
701+ tpls = [(0 , 2 ), (1 , 3 ), (4 , 5 ), (6 , 7 )]
702+ for closed in ('left' , 'right' , 'neither' , 'both' ):
703+ idx = IntervalIndex .from_tuples (tpls , closed = closed )
704+ assert idx .is_non_overlapping_monotonic is False
705+
706+ idx = IntervalIndex .from_tuples (reversed (tpls ), closed = closed )
707+ assert idx .is_non_overlapping_monotonic is False
708+
709+ # Should be False in all cases (non-monotonic)
710+ tpls = [(0 , 1 ), (2 , 3 ), (6 , 7 ), (4 , 5 )]
711+ for closed in ('left' , 'right' , 'neither' , 'both' ):
712+ idx = IntervalIndex .from_tuples (tpls , closed = closed )
713+ assert idx .is_non_overlapping_monotonic is False
714+
715+ idx = IntervalIndex .from_tuples (reversed (tpls ), closed = closed )
716+ assert idx .is_non_overlapping_monotonic is False
717+
718+ # Should be False for closed='both', overwise True (GH16560)
719+ idx = IntervalIndex .from_breaks (range (4 ), closed = 'both' )
720+ assert idx .is_non_overlapping_monotonic is False
721+
722+ for closed in ('left' , 'right' , 'neither' ):
723+ idx = IntervalIndex .from_breaks (range (4 ), closed = closed )
724+ assert idx .is_non_overlapping_monotonic is True
725+
684726
685727class TestIntervalRange (object ):
686728
0 commit comments