@@ -802,8 +802,7 @@ def astype_nansafe(arr, dtype, copy: bool = True, skipna: bool = False):
802
802
return arr .astype (dtype )
803
803
804
804
raise TypeError (
805
- "cannot astype a datetimelike from [{from_dtype}] "
806
- "to [{to_dtype}]" .format (from_dtype = arr .dtype , to_dtype = dtype )
805
+ f"cannot astype a datetimelike from [{ arr .dtype } ] " f"to [{ dtype } ]"
807
806
)
808
807
809
808
elif is_timedelta64_dtype (arr ):
@@ -825,8 +824,7 @@ def astype_nansafe(arr, dtype, copy: bool = True, skipna: bool = False):
825
824
return arr .astype (_TD_DTYPE , copy = copy )
826
825
827
826
raise TypeError (
828
- "cannot astype a timedelta from [{from_dtype}] "
829
- "to [{to_dtype}]" .format (from_dtype = arr .dtype , to_dtype = dtype )
827
+ f"cannot astype a timedelta from [{ arr .dtype } ] " f"to [{ dtype } ]"
830
828
)
831
829
832
830
elif np .issubdtype (arr .dtype , np .floating ) and np .issubdtype (dtype , np .integer ):
@@ -853,8 +851,11 @@ def astype_nansafe(arr, dtype, copy: bool = True, skipna: bool = False):
853
851
return astype_nansafe (to_timedelta (arr ).values , dtype , copy = copy )
854
852
855
853
if dtype .name in ("datetime64" , "timedelta64" ):
856
- msg = "The '{dtype}' dtype has no unit. Please pass in '{dtype}[ns]' instead."
857
- raise ValueError (msg .format (dtype = dtype .name ))
854
+ msg = (
855
+ f"The '{ dtype .name } ' dtype has no unit. Please pass in "
856
+ f"'{ dtype .name } [ns]' instead."
857
+ )
858
+ raise ValueError (msg )
858
859
859
860
if copy or is_object_dtype (arr ) or is_object_dtype (dtype ):
860
861
# Explicit copy, or required since NumPy can't view from / to object.
@@ -1124,8 +1125,8 @@ def maybe_cast_to_datetime(value, dtype, errors: str = "raise"):
1124
1125
1125
1126
# Force the dtype if needed.
1126
1127
msg = (
1127
- "The '{dtype}' dtype has no unit. "
1128
- "Please pass in '{dtype}[ns]' instead."
1128
+ f "The '{ dtype . name } ' dtype has no unit. "
1129
+ f "Please pass in '{ dtype . name } [ns]' instead."
1129
1130
)
1130
1131
1131
1132
if is_datetime64 and not is_dtype_equal (dtype , _NS_DTYPE ):
@@ -1134,13 +1135,10 @@ def maybe_cast_to_datetime(value, dtype, errors: str = "raise"):
1134
1135
# e.g., [ps], [fs], [as]
1135
1136
if dtype <= np .dtype ("M8[ns]" ):
1136
1137
if dtype .name == "datetime64" :
1137
- raise ValueError (msg . format ( dtype = dtype . name ) )
1138
+ raise ValueError (msg )
1138
1139
dtype = _NS_DTYPE
1139
1140
else :
1140
- raise TypeError (
1141
- "cannot convert datetimelike to "
1142
- "dtype [{dtype}]" .format (dtype = dtype )
1143
- )
1141
+ raise TypeError (f"cannot convert datetimelike to dtype [{ dtype } ]" )
1144
1142
elif is_datetime64tz :
1145
1143
1146
1144
# our NaT doesn't support tz's
@@ -1155,13 +1153,10 @@ def maybe_cast_to_datetime(value, dtype, errors: str = "raise"):
1155
1153
# e.g., [ps], [fs], [as]
1156
1154
if dtype <= np .dtype ("m8[ns]" ):
1157
1155
if dtype .name == "timedelta64" :
1158
- raise ValueError (msg . format ( dtype = dtype . name ) )
1156
+ raise ValueError (msg )
1159
1157
dtype = _TD_DTYPE
1160
1158
else :
1161
- raise TypeError (
1162
- "cannot convert timedeltalike to "
1163
- "dtype [{dtype}]" .format (dtype = dtype )
1164
- )
1159
+ raise TypeError (f"cannot convert timedeltalike to dtype [{ dtype } ]" )
1165
1160
1166
1161
if is_scalar (value ):
1167
1162
if value == iNaT or isna (value ):
@@ -1213,7 +1208,7 @@ def maybe_cast_to_datetime(value, dtype, errors: str = "raise"):
1213
1208
return tslib .ints_to_pydatetime (ints )
1214
1209
1215
1210
# we have a non-castable dtype that was passed
1216
- raise TypeError ("Cannot cast datetime64 to {dtype}" . format ( dtype = dtype ) )
1211
+ raise TypeError (f "Cannot cast datetime64 to { dtype } " )
1217
1212
1218
1213
else :
1219
1214
@@ -1477,7 +1472,7 @@ def maybe_cast_to_integer_array(arr, dtype, copy: bool = False):
1477
1472
except OverflowError :
1478
1473
raise OverflowError (
1479
1474
"The elements provided in the data cannot all be "
1480
- "casted to the dtype {dtype}" . format ( dtype = dtype )
1475
+ f "casted to the dtype { dtype } "
1481
1476
)
1482
1477
1483
1478
if np .array_equal (arr , casted ):
0 commit comments