@@ -179,8 +179,8 @@ cdef class IntervalMixin:
179
179
When `other` is not closed exactly the same as self.
180
180
"""
181
181
if self .closed != other.closed:
182
- msg = " '{}.closed' is '{}', expected '{}'."
183
- raise ValueError (msg.format(name, other.closed, self .closed) )
182
+ msg = f " '{name }.closed' is '{other.closed }', expected '{self.closed }'."
183
+ raise ValueError (msg)
184
184
185
185
186
186
cdef _interval_like(other):
@@ -308,17 +308,16 @@ cdef class Interval(IntervalMixin):
308
308
self ._validate_endpoint(right)
309
309
310
310
if closed not in _VALID_CLOSED:
311
- msg = " invalid option for 'closed': {closed}" .format( closed = closed)
311
+ msg = f " invalid option for 'closed': {closed}"
312
312
raise ValueError (msg)
313
313
if not left <= right:
314
314
raise ValueError (' left side of interval must be <= right side' )
315
315
if (isinstance (left, Timestamp) and
316
316
not tz_compare(left.tzinfo, right.tzinfo)):
317
317
# GH 18538
318
- msg = (" left and right must have the same time zone, got "
319
- " '{left_tz}' and '{right_tz}'" )
320
- raise ValueError (msg.format(left_tz = left.tzinfo,
321
- right_tz = right.tzinfo))
318
+ msg = (f" left and right must have the same time zone, got "
319
+ f" '{left.tzinfo}' and '{right.tzinfo}'" )
320
+ raise ValueError (msg)
322
321
self .left = left
323
322
self .right = right
324
323
self .closed = closed
@@ -359,8 +358,7 @@ cdef class Interval(IntervalMixin):
359
358
name = type (self ).__name__
360
359
other = type (other).__name__
361
360
op_str = {Py_LT: ' <' , Py_LE: ' <=' , Py_GT: ' >' , Py_GE: ' >=' }[op]
362
- raise TypeError (' unorderable types: {name}() {op} {other}()'
363
- .format(name = name, op = op_str, other = other))
361
+ raise TypeError (f' unorderable types: {name}() {op_str} {other}()' )
364
362
365
363
def __reduce__ (self ):
366
364
args = (self .left, self .right, self .closed)
@@ -381,17 +379,15 @@ cdef class Interval(IntervalMixin):
381
379
382
380
left , right = self ._repr_base()
383
381
name = type (self ).__name__
384
- repr_str = ' {name}({left!r}, {right!r}, closed={closed!r})' .format(
385
- name = name, left = left, right = right, closed = self .closed)
382
+ repr_str = f' {name}({left!r}, {right!r}, closed={self.closed!r})'
386
383
return repr_str
387
384
388
385
def __str__(self ) -> str:
389
386
390
387
left , right = self ._repr_base()
391
388
start_symbol = ' [' if self .closed_left else ' ('
392
389
end_symbol = ' ]' if self .closed_right else ' )'
393
- return '{start}{left}, {right}{end}'.format(
394
- start = start_symbol, left = left, right = right, end = end_symbol)
390
+ return f'{start_symbol}{left}, {right}{end_symbol}'
395
391
396
392
def __add__(self , y ):
397
393
if isinstance (y, numbers.Number):
@@ -477,8 +473,8 @@ cdef class Interval(IntervalMixin):
477
473
False
478
474
"""
479
475
if not isinstance (other, Interval):
480
- msg = ' `other` must be an Interval, got {other}'
481
- raise TypeError (msg.format( other = type (other).__name__) )
476
+ msg = f ' `other` must be an Interval, got {type( other).__name__ }'
477
+ raise TypeError (msg)
482
478
483
479
# equality is okay if both endpoints are closed (overlap at a point)
484
480
op1 = le if (self .closed_left and other.closed_right) else lt
@@ -529,8 +525,8 @@ def intervals_to_interval_bounds(ndarray intervals,
529
525
continue
530
526
531
527
if not isinstance (interval, Interval):
532
- raise TypeError (" type {typ } with value {iv} is not an interval "
533
- .format( typ = type ( interval), iv = interval) )
528
+ raise TypeError (f " type {type(interval) } with value "
529
+ f " { interval} is not an interval" )
534
530
535
531
left[i] = interval.left
536
532
right[i] = interval.right
0 commit comments