@@ -70,15 +70,15 @@ def f(self):
7070 return result
7171
7272 f .__name__ = name
73- f .__doc__ = "\n {}\n " . format ( docstring )
73+ f .__doc__ = f "\n { docstring } \n "
7474 return property (f )
7575
7676
7777def _td_array_cmp (cls , op ):
7878 """
7979 Wrap comparison operations to convert timedelta-like to timedelta64
8080 """
81- opname = "__{name}__" . format ( name = op .__name__ )
81+ opname = f "__{ op .__name__ } __"
8282 nat_result = opname == "__ne__"
8383
8484 @unpack_zerodim_and_defer (opname )
@@ -215,10 +215,10 @@ def __init__(self, values, dtype=_TD_DTYPE, freq=None, copy=False):
215215
216216 if not isinstance (values , np .ndarray ):
217217 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."
220220 )
221- raise ValueError (msg . format ( type ( values ). __name__ ) )
221+ raise ValueError (msg )
222222 if values .ndim != 1 :
223223 raise ValueError ("Only 1-dimensional input arrays are supported." )
224224
@@ -351,10 +351,7 @@ def _validate_fill_value(self, fill_value):
351351 elif isinstance (fill_value , (timedelta , np .timedelta64 , Tick )):
352352 fill_value = Timedelta (fill_value ).value
353353 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 } '." )
358355 return fill_value
359356
360357 def astype (self , dtype , copy = True ):
@@ -461,9 +458,7 @@ def _format_native_types(self, na_rep="NaT", date_format=None):
461458 def _add_offset (self , other ):
462459 assert not isinstance (other , Tick )
463460 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__ } "
467462 )
468463
469464 def _add_delta (self , delta ):
@@ -523,9 +518,7 @@ def _addsub_offset_array(self, other, op):
523518 return super ()._addsub_offset_array (other , op )
524519 except AttributeError :
525520 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__ } "
529522 )
530523
531524 def __mul__ (self , other ):
@@ -634,9 +627,7 @@ def __rtruediv__(self, other):
634627
635628 elif lib .is_scalar (other ):
636629 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__ } "
640631 )
641632
642633 if not hasattr (other , "dtype" ):
@@ -659,9 +650,7 @@ def __rtruediv__(self, other):
659650
660651 else :
661652 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__ } "
665654 )
666655
667656 def __floordiv__ (self , other ):
@@ -724,11 +713,7 @@ def __floordiv__(self, other):
724713
725714 else :
726715 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__ } " )
732717
733718 def __rfloordiv__ (self , other ):
734719 if isinstance (other , (ABCSeries , ABCDataFrame , ABCIndexClass )):
@@ -749,9 +734,7 @@ def __rfloordiv__(self, other):
749734 return result
750735
751736 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__ } "
755738 )
756739
757740 if not hasattr (other , "dtype" ):
@@ -779,11 +762,7 @@ def __rfloordiv__(self, other):
779762
780763 else :
781764 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__ } " )
787766
788767 def __mod__ (self , other ):
789768 # 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"):
10561035
10571036 else :
10581037 # 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]" )
10641039
10651040 data = np .array (data , copy = copy )
10661041 if data .ndim != 1 :
@@ -1096,7 +1071,7 @@ def ints_to_td64ns(data, unit="ns"):
10961071 copy_made = True
10971072
10981073 if unit != "ns" :
1099- dtype_str = "timedelta64[{unit}]" . format ( unit = unit )
1074+ dtype_str = f "timedelta64[{ unit } ]"
11001075 data = data .view (dtype_str )
11011076
11021077 # TODO: watch out for overflows when converting from lower-resolution
0 commit comments