@@ -243,3 +243,44 @@ def test_loc_getitem_frame(self):
243
243
# partial missing
244
244
with pytest .raises (KeyError ):
245
245
df .loc [[10 , 4 ]]
246
+
247
+ def test_is_non_overlapping_monotonic (self ):
248
+ # Verify that a Python Boolean is returned (GH17237)
249
+ for closed in ('left' , 'right' , 'neither' , 'both' ):
250
+ idx = IntervalIndex .from_breaks (range (4 ), closed = closed )
251
+ assert type (idx .is_non_overlapping_monotonic ) is bool
252
+
253
+ # Should be True in all cases
254
+ tpls = [(0 , 1 ), (2 , 3 ), (4 , 5 ), (6 , 7 )]
255
+ for closed in ('left' , 'right' , 'neither' , 'both' ):
256
+ idx = IntervalIndex .from_tuples (tpls , closed = closed )
257
+ assert idx .is_non_overlapping_monotonic is True
258
+
259
+ idx = IntervalIndex .from_tuples (reversed (tpls ), closed = closed )
260
+ assert idx .is_non_overlapping_monotonic is True
261
+
262
+ # Should be False in all cases (overlapping)
263
+ tpls = [(0 , 2 ), (1 , 3 ), (4 , 5 ), (6 , 7 )]
264
+ for closed in ('left' , 'right' , 'neither' , 'both' ):
265
+ idx = IntervalIndex .from_tuples (tpls , closed = closed )
266
+ assert idx .is_non_overlapping_monotonic is False
267
+
268
+ idx = IntervalIndex .from_tuples (reversed (tpls ), closed = closed )
269
+ assert idx .is_non_overlapping_monotonic is False
270
+
271
+ # Should be False in all cases (non-monotonic)
272
+ tpls = [(0 , 1 ), (2 , 3 ), (6 , 7 ), (4 , 5 )]
273
+ for closed in ('left' , 'right' , 'neither' , 'both' ):
274
+ idx = IntervalIndex .from_tuples (tpls , closed = closed )
275
+ assert idx .is_non_overlapping_monotonic is False
276
+
277
+ idx = IntervalIndex .from_tuples (reversed (tpls ), closed = closed )
278
+ assert idx .is_non_overlapping_monotonic is False
279
+
280
+ # Should be False for closed='both', overwise True (GH16560)
281
+ idx = IntervalIndex .from_breaks (range (4 ), closed = 'both' )
282
+ assert idx .is_non_overlapping_monotonic is False
283
+
284
+ for closed in ('left' , 'right' , 'neither' ):
285
+ idx = IntervalIndex .from_breaks (range (4 ), closed = closed )
286
+ assert idx .is_non_overlapping_monotonic is True
0 commit comments