Skip to content

Commit bfd98d4

Browse files
EydenVillanuevaproost
authored andcommitted
STY: Replace .format() to fstrings (pandas-dev#30278)
1 parent 96b71d1 commit bfd98d4

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

pandas/core/missing.py

+7-14
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ def clean_fill_method(method, allow_nearest=False):
8888
valid_methods.append("nearest")
8989
expecting = "pad (ffill), backfill (bfill) or nearest"
9090
if method not in valid_methods:
91-
msg = "Invalid fill method. Expecting {expecting}. Got {method}".format(
92-
expecting=expecting, method=method
93-
)
94-
raise ValueError(msg)
91+
raise ValueError(f"Invalid fill method. Expecting {expecting}. Got {method}")
9592
return method
9693

9794

@@ -119,10 +116,7 @@ def clean_interp_method(method, **kwargs):
119116
if method in ("spline", "polynomial") and order is None:
120117
raise ValueError("You must specify the order of the spline or polynomial.")
121118
if method not in valid:
122-
raise ValueError(
123-
"method must be one of {valid}. Got '{method}' "
124-
"instead.".format(valid=valid, method=method)
125-
)
119+
raise ValueError(f"method must be one of {valid}. Got '{method}' instead.")
126120

127121
return method
128122

@@ -212,7 +206,7 @@ def interpolate_1d(
212206
limit_direction = limit_direction.lower()
213207
if limit_direction not in valid_limit_directions:
214208
raise ValueError(
215-
f"Invalid limit_direction: expecting one of "
209+
"Invalid limit_direction: expecting one of "
216210
f"{valid_limit_directions}, got '{limit_direction}'."
217211
)
218212

@@ -221,8 +215,8 @@ def interpolate_1d(
221215
limit_area = limit_area.lower()
222216
if limit_area not in valid_limit_areas:
223217
raise ValueError(
224-
"Invalid limit_area: expecting one of {}, got "
225-
"{}.".format(valid_limit_areas, limit_area)
218+
f"Invalid limit_area: expecting one of {valid_limit_areas}, got "
219+
f"{limit_area}."
226220
)
227221

228222
# default limit is unlimited GH #16282
@@ -328,7 +322,7 @@ def _interpolate_scipy_wrapper(
328322
Returns an array interpolated at new_x. Add any new methods to
329323
the list in _clean_interp_method.
330324
"""
331-
extra = "{method} interpolation requires SciPy.".format(method=method)
325+
extra = f"{method} interpolation requires SciPy."
332326
import_optional_dependency("scipy", extra=extra)
333327
from scipy import interpolate
334328

@@ -375,8 +369,7 @@ def _interpolate_scipy_wrapper(
375369
# GH #10633, #24014
376370
if isna(order) or (order <= 0):
377371
raise ValueError(
378-
"order needs to be specified and greater than 0; "
379-
"got order: {}".format(order)
372+
f"order needs to be specified and greater than 0; got order: {order}"
380373
)
381374
terp = interpolate.UnivariateSpline(x, y, k=order, **kwargs)
382375
new_y = terp(new_x)

pandas/core/nanops.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1301,9 +1301,7 @@ def _ensure_numeric(x):
13011301
x = complex(x)
13021302
except ValueError:
13031303
# e.g. "foo"
1304-
raise TypeError(
1305-
"Could not convert {value!s} to numeric".format(value=x)
1306-
)
1304+
raise TypeError(f"Could not convert {x} to numeric")
13071305
return x
13081306

13091307

pandas/tests/indexes/datetimes/test_partial_slicing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def test_partial_slicing_dataframe(self):
274274
result = df["a"][ts_string]
275275
assert isinstance(result, np.int64)
276276
assert result == expected
277-
msg = r"^'{}'$".format(ts_string)
277+
msg = fr"^'{ts_string}'$"
278278
with pytest.raises(KeyError, match=msg):
279279
df[ts_string]
280280

@@ -302,7 +302,7 @@ def test_partial_slicing_dataframe(self):
302302
result = df["a"][ts_string]
303303
assert isinstance(result, np.int64)
304304
assert result == 2
305-
msg = r"^'{}'$".format(ts_string)
305+
msg = fr"^'{ts_string}'$"
306306
with pytest.raises(KeyError, match=msg):
307307
df[ts_string]
308308

@@ -311,7 +311,7 @@ def test_partial_slicing_dataframe(self):
311311
for fmt, res in list(zip(formats, resolutions))[rnum + 1 :]:
312312
ts = index[1] + Timedelta("1 " + res)
313313
ts_string = ts.strftime(fmt)
314-
msg = r"^'{}'$".format(ts_string)
314+
msg = fr"^'{ts_string}'$"
315315
with pytest.raises(KeyError, match=msg):
316316
df["a"][ts_string]
317317
with pytest.raises(KeyError, match=msg):

0 commit comments

Comments
 (0)