@@ -70,15 +70,15 @@ def f(self):
70
70
return result
71
71
72
72
f .__name__ = name
73
- f .__doc__ = "\n {}\n " . format ( docstring )
73
+ f .__doc__ = f "\n { docstring } \n "
74
74
return property (f )
75
75
76
76
77
77
def _td_array_cmp (cls , op ):
78
78
"""
79
79
Wrap comparison operations to convert timedelta-like to timedelta64
80
80
"""
81
- opname = "__{name}__" . format ( name = op .__name__ )
81
+ opname = f "__{ op .__name__ } __"
82
82
nat_result = opname == "__ne__"
83
83
84
84
@unpack_zerodim_and_defer (opname )
@@ -215,10 +215,10 @@ def __init__(self, values, dtype=_TD_DTYPE, freq=None, copy=False):
215
215
216
216
if not isinstance (values , np .ndarray ):
217
217
msg = (
218
- "Unexpected type '{}'. 'values' must be a TimedeltaArray "
219
- "ndarray, or Series or Index containing one of those."
218
+ f "Unexpected type '{ type ( values ). __name__ } '. 'values' must be a"
219
+ " TimedeltaArray ndarray, or Series or Index containing one of those."
220
220
)
221
- raise ValueError (msg . format ( type ( values ). __name__ ) )
221
+ raise ValueError (msg )
222
222
if values .ndim != 1 :
223
223
raise ValueError ("Only 1-dimensional input arrays are supported." )
224
224
@@ -351,10 +351,7 @@ def _validate_fill_value(self, fill_value):
351
351
elif isinstance (fill_value , (timedelta , np .timedelta64 , Tick )):
352
352
fill_value = Timedelta (fill_value ).value
353
353
else :
354
- raise ValueError (
355
- "'fill_value' should be a Timedelta. "
356
- "Got '{got}'." .format (got = fill_value )
357
- )
354
+ raise ValueError (f"'fill_value' should be a Timedelta. Got '{ fill_value } '." )
358
355
return fill_value
359
356
360
357
def astype (self , dtype , copy = True ):
@@ -461,9 +458,7 @@ def _format_native_types(self, na_rep="NaT", date_format=None):
461
458
def _add_offset (self , other ):
462
459
assert not isinstance (other , Tick )
463
460
raise TypeError (
464
- "cannot add the type {typ} to a {cls}" .format (
465
- typ = type (other ).__name__ , cls = type (self ).__name__
466
- )
461
+ f"cannot add the type { type (other ).__name__ } to a { type (self ).__name__ } "
467
462
)
468
463
469
464
def _add_delta (self , delta ):
@@ -523,9 +518,7 @@ def _addsub_offset_array(self, other, op):
523
518
return super ()._addsub_offset_array (other , op )
524
519
except AttributeError :
525
520
raise TypeError (
526
- "Cannot add/subtract non-tick DateOffset to {cls}" .format (
527
- cls = type (self ).__name__
528
- )
521
+ f"Cannot add/subtract non-tick DateOffset to { type (self ).__name__ } "
529
522
)
530
523
531
524
def __mul__ (self , other ):
@@ -634,9 +627,7 @@ def __rtruediv__(self, other):
634
627
635
628
elif lib .is_scalar (other ):
636
629
raise TypeError (
637
- "Cannot divide {typ} by {cls}" .format (
638
- typ = type (other ).__name__ , cls = type (self ).__name__
639
- )
630
+ f"Cannot divide { type (other ).__name__ } by { type (self ).__name__ } "
640
631
)
641
632
642
633
if not hasattr (other , "dtype" ):
@@ -659,9 +650,7 @@ def __rtruediv__(self, other):
659
650
660
651
else :
661
652
raise TypeError (
662
- "Cannot divide {dtype} data by {cls}" .format (
663
- dtype = other .dtype , cls = type (self ).__name__
664
- )
653
+ f"Cannot divide { other .dtype } data by { type (self ).__name__ } "
665
654
)
666
655
667
656
def __floordiv__ (self , other ):
@@ -724,11 +713,7 @@ def __floordiv__(self, other):
724
713
725
714
else :
726
715
dtype = getattr (other , "dtype" , type (other ).__name__ )
727
- raise TypeError (
728
- "Cannot divide {typ} by {cls}" .format (
729
- typ = dtype , cls = type (self ).__name__
730
- )
731
- )
716
+ raise TypeError (f"Cannot divide { dtype } by { type (self ).__name__ } " )
732
717
733
718
def __rfloordiv__ (self , other ):
734
719
if isinstance (other , (ABCSeries , ABCDataFrame , ABCIndexClass )):
@@ -749,9 +734,7 @@ def __rfloordiv__(self, other):
749
734
return result
750
735
751
736
raise TypeError (
752
- "Cannot divide {typ} by {cls}" .format (
753
- typ = type (other ).__name__ , cls = type (self ).__name__
754
- )
737
+ f"Cannot divide { type (other ).__name__ } by { type (self ).__name__ } "
755
738
)
756
739
757
740
if not hasattr (other , "dtype" ):
@@ -779,11 +762,7 @@ def __rfloordiv__(self, other):
779
762
780
763
else :
781
764
dtype = getattr (other , "dtype" , type (other ).__name__ )
782
- raise TypeError (
783
- "Cannot divide {typ} by {cls}" .format (
784
- typ = dtype , cls = type (self ).__name__
785
- )
786
- )
765
+ raise TypeError (f"Cannot divide { dtype } by { type (self ).__name__ } " )
787
766
788
767
def __mod__ (self , other ):
789
768
# Note: This is a naive implementation, can likely be optimized
@@ -1056,11 +1035,7 @@ def sequence_to_td64ns(data, copy=False, unit="ns", errors="raise"):
1056
1035
1057
1036
else :
1058
1037
# This includes datetime64-dtype, see GH#23539, GH#29794
1059
- raise TypeError (
1060
- "dtype {dtype} cannot be converted to timedelta64[ns]" .format (
1061
- dtype = data .dtype
1062
- )
1063
- )
1038
+ raise TypeError (f"dtype { data .dtype } cannot be converted to timedelta64[ns]" )
1064
1039
1065
1040
data = np .array (data , copy = copy )
1066
1041
if data .ndim != 1 :
@@ -1096,7 +1071,7 @@ def ints_to_td64ns(data, unit="ns"):
1096
1071
copy_made = True
1097
1072
1098
1073
if unit != "ns" :
1099
- dtype_str = "timedelta64[{unit}]" . format ( unit = unit )
1074
+ dtype_str = f "timedelta64[{ unit } ]"
1100
1075
data = data .view (dtype_str )
1101
1076
1102
1077
# TODO: watch out for overflows when converting from lower-resolution
0 commit comments