@@ -115,8 +115,8 @@ def __init__(self, values, placement, ndim=None):
115
115
116
116
if self ._validate_ndim and self .ndim and len (self .mgr_locs ) != len (self .values ):
117
117
raise ValueError (
118
- "Wrong number of items passed {val}, placement implies "
119
- "{mgr}" . format ( val = len (self .values ), mgr = len ( self . mgr_locs ))
118
+ f "Wrong number of items passed { len ( self . values ) } , "
119
+ f"placement implies { len (self .mgr_locs )} "
120
120
)
121
121
122
122
def _check_ndim (self , values , ndim ):
@@ -144,9 +144,10 @@ def _check_ndim(self, values, ndim):
144
144
ndim = values .ndim
145
145
146
146
if self ._validate_ndim and values .ndim != ndim :
147
- msg = "Wrong number of dimensions. values.ndim != ndim [{} != {}]"
148
- raise ValueError (msg .format (values .ndim , ndim ))
149
-
147
+ raise ValueError (
148
+ "Wrong number of dimensions. "
149
+ f"values.ndim != ndim [{ values .ndim } != { ndim } ]"
150
+ )
150
151
return ndim
151
152
152
153
@property
@@ -184,7 +185,7 @@ def is_categorical_astype(self, dtype):
184
185
if dtype is Categorical or dtype is CategoricalDtype :
185
186
# this is a pd.Categorical, but is not
186
187
# a valid type for astypeing
187
- raise TypeError ("invalid type {0 } for astype" . format ( dtype ) )
188
+ raise TypeError (f "invalid type { dtype } for astype" )
188
189
189
190
elif is_categorical_dtype (dtype ):
190
191
return True
@@ -264,18 +265,14 @@ def __repr__(self) -> str:
264
265
name = type (self ).__name__
265
266
if self ._is_single_block :
266
267
267
- result = "{name}: {len} dtype: {dtype}" .format (
268
- name = name , len = len (self ), dtype = self .dtype
269
- )
268
+ result = f"{ name } : { len (self )} dtype: { self .dtype } "
270
269
271
270
else :
272
271
273
272
shape = " x " .join (pprint_thing (s ) for s in self .shape )
274
- result = "{name}: {index}, {shape}, dtype: {dtype}" .format (
275
- name = name ,
276
- index = pprint_thing (self .mgr_locs .indexer ),
277
- shape = shape ,
278
- dtype = self .dtype ,
273
+ result = (
274
+ f"{ name } : { pprint_thing (self .mgr_locs .indexer )} , "
275
+ f"{ shape } , dtype: { self .dtype } "
279
276
)
280
277
281
278
return result
@@ -329,7 +326,7 @@ def ftype(self):
329
326
dtype = self .dtype .subtype
330
327
else :
331
328
dtype = self .dtype
332
- return "{dtype}:{ftype}" . format ( dtype = dtype , ftype = self ._ftype )
329
+ return f "{ dtype } :{ self ._ftype } "
333
330
334
331
def merge (self , other ):
335
332
return _merge_blocks ([self , other ])
@@ -544,15 +541,15 @@ def astype(self, dtype, copy: bool = False, errors: str = "raise"):
544
541
545
542
if errors not in errors_legal_values :
546
543
invalid_arg = (
547
- "Expected value of kwarg 'errors' to be one of {}. "
548
- " Supplied value is '{}'". format ( list ( errors_legal_values ), errors )
544
+ "Expected value of kwarg 'errors' to be one of "
545
+ f" { list ( errors_legal_values ) } . Supplied value is '{ errors } '"
549
546
)
550
547
raise ValueError (invalid_arg )
551
548
552
549
if inspect .isclass (dtype ) and issubclass (dtype , ExtensionDtype ):
553
550
msg = (
554
- "Expected an instance of {}, but got the class instead. "
555
- "Try instantiating 'dtype'." . format ( dtype . __name__ )
551
+ f "Expected an instance of { dtype . __name__ } , "
552
+ "but got the class instead. Try instantiating 'dtype'."
556
553
)
557
554
raise TypeError (msg )
558
555
@@ -613,15 +610,9 @@ def astype(self, dtype, copy: bool = False, errors: str = "raise"):
613
610
if newb .is_numeric and self .is_numeric :
614
611
if newb .shape != self .shape :
615
612
raise TypeError (
616
- "cannot set astype for copy = [{copy}] for dtype "
617
- "({dtype} [{shape}]) to different shape "
618
- "({newb_dtype} [{newb_shape}])" .format (
619
- copy = copy ,
620
- dtype = self .dtype .name ,
621
- shape = self .shape ,
622
- newb_dtype = newb .dtype .name ,
623
- newb_shape = newb .shape ,
624
- )
613
+ f"cannot set astype for copy = [{ copy } ] for dtype "
614
+ f"({ self .dtype .name } [{ self .shape } ]) to different shape "
615
+ f"({ newb .dtype .name } [{ newb .shape } ])"
625
616
)
626
617
return newb
627
618
@@ -658,7 +649,7 @@ def to_native_types(self, slicer=None, na_rep="nan", quoting=None, **kwargs):
658
649
659
650
if not self .is_object and not quoting :
660
651
itemsize = writers .word_len (na_rep )
661
- values = values .astype ("<U{size}" . format ( size = itemsize ) )
652
+ values = values .astype (f "<U{ itemsize } " )
662
653
else :
663
654
values = np .array (values , dtype = "object" )
664
655
@@ -1045,8 +1036,7 @@ def coerce_to_target_dtype(self, other):
1045
1036
return self .astype (object )
1046
1037
1047
1038
raise AssertionError (
1048
- "possible recursion in "
1049
- "coerce_to_target_dtype: {} {}" .format (self , other )
1039
+ f"possible recursion in coerce_to_target_dtype: { self } { other } "
1050
1040
)
1051
1041
1052
1042
elif self .is_timedelta or is_timedelta64_dtype (dtype ):
@@ -1056,8 +1046,7 @@ def coerce_to_target_dtype(self, other):
1056
1046
return self .astype (object )
1057
1047
1058
1048
raise AssertionError (
1059
- "possible recursion in "
1060
- "coerce_to_target_dtype: {} {}" .format (self , other )
1049
+ f"possible recursion in coerce_to_target_dtype: { self } { other } "
1061
1050
)
1062
1051
1063
1052
try :
@@ -1202,8 +1191,7 @@ def _interpolate(
1202
1191
if method in ("krogh" , "piecewise_polynomial" , "pchip" ):
1203
1192
if not index .is_monotonic :
1204
1193
raise ValueError (
1205
- "{0} interpolation requires that the "
1206
- "index be monotonic." .format (method )
1194
+ f"{ method } interpolation requires that the index be monotonic."
1207
1195
)
1208
1196
# process 1-d slices in the axis direction
1209
1197
@@ -1585,15 +1573,15 @@ def iget(self, col):
1585
1573
if self .ndim == 2 and isinstance (col , tuple ):
1586
1574
col , loc = col
1587
1575
if not com .is_null_slice (col ) and col != 0 :
1588
- raise IndexError ("{0 } only contains one item". format ( self ) )
1576
+ raise IndexError (f" { self } only contains one item" )
1589
1577
elif isinstance (col , slice ):
1590
1578
if col != slice (None ):
1591
1579
raise NotImplementedError (col )
1592
1580
return self .values [[loc ]]
1593
1581
return self .values [loc ]
1594
1582
else :
1595
1583
if col != 0 :
1596
- raise IndexError ("{0 } only contains one item". format ( self ) )
1584
+ raise IndexError (f" { self } only contains one item" )
1597
1585
return self .values
1598
1586
1599
1587
def should_store (self , value ):
@@ -2312,7 +2300,7 @@ def _slice(self, slicer):
2312
2300
if isinstance (slicer , tuple ):
2313
2301
col , loc = slicer
2314
2302
if not com .is_null_slice (col ) and col != 0 :
2315
- raise IndexError ("{0 } only contains one item". format ( self ) )
2303
+ raise IndexError (f" { self } only contains one item" )
2316
2304
return self .values [loc ]
2317
2305
return self .values [slicer ]
2318
2306
0 commit comments