@@ -702,7 +702,7 @@ def test_astype_categorical(self, dtype):
702702 @pytest .mark .parametrize ("cls" , [CategoricalDtype , DatetimeTZDtype , IntervalDtype ])
703703 def test_astype_categoricaldtype_class_raises (self , cls ):
704704 df = DataFrame ({"A" : ["a" , "a" , "b" , "c" ]})
705- xpr = "Expected an instance of {}" . format ( cls .__name__ )
705+ xpr = f "Expected an instance of { cls .__name__ } "
706706 with pytest .raises (TypeError , match = xpr ):
707707 df .astype ({"A" : cls })
708708
@@ -827,7 +827,7 @@ def test_df_where_change_dtype(self):
827827 def test_astype_from_datetimelike_to_objectt (self , dtype , unit ):
828828 # tests astype to object dtype
829829 # gh-19223 / gh-12425
830- dtype = "{ }[{}]". format ( dtype , unit )
830+ dtype = f" { dtype } [{ unit } ]"
831831 arr = np .array ([[1 , 2 , 3 ]], dtype = dtype )
832832 df = DataFrame (arr )
833833 result = df .astype (object )
@@ -844,7 +844,7 @@ def test_astype_from_datetimelike_to_objectt(self, dtype, unit):
844844 def test_astype_to_datetimelike_unit (self , arr_dtype , dtype , unit ):
845845 # tests all units from numeric origination
846846 # gh-19223 / gh-12425
847- dtype = "{ }[{}]". format ( dtype , unit )
847+ dtype = f" { dtype } [{ unit } ]"
848848 arr = np .array ([[1 , 2 , 3 ]], dtype = arr_dtype )
849849 df = DataFrame (arr )
850850 result = df .astype (dtype )
@@ -856,7 +856,7 @@ def test_astype_to_datetimelike_unit(self, arr_dtype, dtype, unit):
856856 def test_astype_to_datetime_unit (self , unit ):
857857 # tests all units from datetime origination
858858 # gh-19223
859- dtype = "M8[{}]" . format ( unit )
859+ dtype = f "M8[{ unit } ]"
860860 arr = np .array ([[1 , 2 , 3 ]], dtype = dtype )
861861 df = DataFrame (arr )
862862 result = df .astype (dtype )
@@ -868,7 +868,7 @@ def test_astype_to_datetime_unit(self, unit):
868868 def test_astype_to_timedelta_unit_ns (self , unit ):
869869 # preserver the timedelta conversion
870870 # gh-19223
871- dtype = "m8[{}]" . format ( unit )
871+ dtype = f "m8[{ unit } ]"
872872 arr = np .array ([[1 , 2 , 3 ]], dtype = dtype )
873873 df = DataFrame (arr )
874874 result = df .astype (dtype )
@@ -880,7 +880,7 @@ def test_astype_to_timedelta_unit_ns(self, unit):
880880 def test_astype_to_timedelta_unit (self , unit ):
881881 # coerce to float
882882 # gh-19223
883- dtype = "m8[{}]" . format ( unit )
883+ dtype = f "m8[{ unit } ]"
884884 arr = np .array ([[1 , 2 , 3 ]], dtype = dtype )
885885 df = DataFrame (arr )
886886 result = df .astype (dtype )
@@ -892,21 +892,21 @@ def test_astype_to_timedelta_unit(self, unit):
892892 def test_astype_to_incorrect_datetimelike (self , unit ):
893893 # trying to astype a m to a M, or vice-versa
894894 # gh-19224
895- dtype = "M8[{}]" . format ( unit )
896- other = "m8[{}]" . format ( unit )
895+ dtype = f "M8[{ unit } ]"
896+ other = f "m8[{ unit } ]"
897897
898898 df = DataFrame (np .array ([[1 , 2 , 3 ]], dtype = dtype ))
899899 msg = (
900- r "cannot astype a datetimelike from \[datetime64\[ns\]\] to "
901- r "\[timedelta64\[{}\]\]"
902- ). format ( unit )
900+ fr "cannot astype a datetimelike from \[datetime64\[ns\]\] to "
901+ fr "\[timedelta64\[{ unit } \]\]"
902+ )
903903 with pytest .raises (TypeError , match = msg ):
904904 df .astype (other )
905905
906906 msg = (
907- r "cannot astype a timedelta from \[timedelta64\[ns\]\] to "
908- r "\[datetime64\[{}\]\]"
909- ). format ( unit )
907+ fr "cannot astype a timedelta from \[timedelta64\[ns\]\] to "
908+ fr "\[datetime64\[{ unit } \]\]"
909+ )
910910 df = DataFrame (np .array ([[1 , 2 , 3 ]], dtype = other ))
911911 with pytest .raises (TypeError , match = msg ):
912912 df .astype (dtype )
0 commit comments