@@ -41,8 +41,7 @@ cdef class IntervalMixin:
41
41
Returns
42
42
-------
43
43
bool
44
- ``True`` if the Interval is closed on the left-side, else
45
- ``False``.
44
+ True if the Interval is closed on the left-side.
46
45
"""
47
46
return self .closed in (' left' , ' both' )
48
47
@@ -56,8 +55,7 @@ cdef class IntervalMixin:
56
55
Returns
57
56
-------
58
57
bool
59
- ``True`` if the Interval is closed on the left-side, else
60
- ``False``.
58
+ True if the Interval is closed on the left-side.
61
59
"""
62
60
return self .closed in (' right' , ' both' )
63
61
@@ -71,8 +69,7 @@ cdef class IntervalMixin:
71
69
Returns
72
70
-------
73
71
bool
74
- ``True`` if the Interval is closed on the left-side, else
75
- ``False``.
72
+ True if the Interval is closed on the left-side.
76
73
"""
77
74
return not self .closed_left
78
75
@@ -86,8 +83,7 @@ cdef class IntervalMixin:
86
83
Returns
87
84
-------
88
85
bool
89
- ``True`` if the Interval is closed on the left-side, else
90
- ``False``.
86
+ True if the Interval is closed on the left-side.
91
87
"""
92
88
return not self .closed_right
93
89
@@ -308,16 +304,14 @@ cdef class Interval(IntervalMixin):
308
304
self ._validate_endpoint(right)
309
305
310
306
if closed not in _VALID_CLOSED:
311
- msg = f" invalid option for 'closed': {closed}"
312
- raise ValueError (msg)
307
+ raise ValueError (f" invalid option for 'closed': {closed}" )
313
308
if not left <= right:
314
- raise ValueError (' left side of interval must be <= right side' )
309
+ raise ValueError (" left side of interval must be <= right side" )
315
310
if (isinstance (left, Timestamp) and
316
311
not tz_compare(left.tzinfo, right.tzinfo)):
317
312
# GH 18538
318
- msg = (f" left and right must have the same time zone, got "
319
- f" {repr(left.tzinfo)}' and {repr(right.tzinfo)}" )
320
- raise ValueError (msg)
313
+ raise ValueError (" left and right must have the same time zone, got "
314
+ f" {repr(left.tzinfo)}' and {repr(right.tzinfo)}" )
321
315
self .left = left
322
316
self .right = right
323
317
self .closed = closed
@@ -326,16 +320,15 @@ cdef class Interval(IntervalMixin):
326
320
# GH 23013
327
321
if not (is_integer_object(endpoint) or is_float_object(endpoint) or
328
322
isinstance (endpoint, (Timestamp, Timedelta))):
329
- msg = (" Only numeric, Timestamp and Timedelta endpoints "
330
- " are allowed when constructing an Interval." )
331
- raise ValueError (msg)
323
+ raise ValueError (" Only numeric, Timestamp and Timedelta endpoints "
324
+ " are allowed when constructing an Interval." )
332
325
333
326
def __hash__ (self ):
334
327
return hash ((self .left, self .right, self .closed))
335
328
336
329
def __contains__ (self , key ):
337
330
if _interval_like(key):
338
- raise TypeError (' __contains__ not defined for two intervals' )
331
+ raise TypeError (" __contains__ not defined for two intervals" )
339
332
return ((self .left < key if self .open_left else self .left <= key) and
340
333
(key < self .right if self .open_right else key <= self .right))
341
334
@@ -358,7 +351,7 @@ cdef class Interval(IntervalMixin):
358
351
name = type (self ).__name__
359
352
other = type (other).__name__
360
353
op_str = {Py_LT: ' <' , Py_LE: ' <=' , Py_GT: ' >' , Py_GE: ' >=' }[op]
361
- raise TypeError (f' unorderable types: {name}() {op_str} {other}()' )
354
+ raise TypeError (f" unorderable types: {name}() {op_str} {other}()" )
362
355
363
356
def __reduce__ (self ):
364
357
args = (self .left, self .right, self .closed)
@@ -437,12 +430,12 @@ cdef class Interval(IntervalMixin):
437
430
Parameters
438
431
----------
439
432
other : Interval
440
- The interval to check against for an overlap.
433
+ Interval to check against for an overlap.
441
434
442
435
Returns
443
436
-------
444
437
bool
445
- `` True`` if the two intervals overlap, else ``False`` .
438
+ True if the two intervals overlap.
446
439
447
440
See Also
448
441
--------
@@ -473,8 +466,8 @@ cdef class Interval(IntervalMixin):
473
466
False
474
467
"""
475
468
if not isinstance (other, Interval):
476
- msg = f ' `other` must be an Interval, got {type(other).__name__} '
477
- raise TypeError (msg )
469
+ raise TypeError ( " `other` must be an Interval, "
470
+ f " got {type(other).__name__} " )
478
471
479
472
# equality is okay if both endpoints are closed (overlap at a point)
480
473
op1 = le if (self .closed_left and other.closed_right) else lt
@@ -494,20 +487,19 @@ def intervals_to_interval_bounds(ndarray intervals,
494
487
Parameters
495
488
----------
496
489
intervals : ndarray
497
- object array of Intervals / nulls
490
+ Object array of Intervals / nulls.
498
491
499
- validate_closed: boolean , default True
500
- boolean indicating if all intervals must be closed on the same side.
492
+ validate_closed: bool , default True
493
+ Boolean indicating if all intervals must be closed on the same side.
501
494
Mismatching closed will raise if True, else return None for closed.
502
495
503
496
Returns
504
497
-------
505
- tuples (left: ndarray object array,
506
- right: ndarray object array,
507
- closed: str )
508
-
498
+ tuple of tuples
499
+ left : ( ndarray, object, array)
500
+ right : (ndarray, object, array )
501
+ closed: str
509
502
"""
510
-
511
503
cdef:
512
504
object closed = None , interval
513
505
int64_t n = len (intervals)
@@ -536,8 +528,7 @@ def intervals_to_interval_bounds(ndarray intervals,
536
528
elif closed != interval.closed:
537
529
closed = None
538
530
if validate_closed:
539
- msg = ' intervals must all be closed on the same side'
540
- raise ValueError (msg)
531
+ raise ValueError (" intervals must all be closed on the same side" )
541
532
542
533
return left, right, closed
543
534
0 commit comments