Skip to content

STY: Replace .format() to fstrings #30278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions pandas/core/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ def clean_fill_method(method, allow_nearest=False):
valid_methods.append("nearest")
expecting = "pad (ffill), backfill (bfill) or nearest"
if method not in valid_methods:
msg = "Invalid fill method. Expecting {expecting}. Got {method}".format(
expecting=expecting, method=method
)
raise ValueError(msg)
raise ValueError(f"Invalid fill method. Expecting {expecting}. Got {method}")
return method


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

return method

Expand Down Expand Up @@ -212,7 +206,7 @@ def interpolate_1d(
limit_direction = limit_direction.lower()
if limit_direction not in valid_limit_directions:
raise ValueError(
f"Invalid limit_direction: expecting one of "
"Invalid limit_direction: expecting one of "
f"{valid_limit_directions}, got '{limit_direction}'."
)

Expand All @@ -221,8 +215,8 @@ def interpolate_1d(
limit_area = limit_area.lower()
if limit_area not in valid_limit_areas:
raise ValueError(
"Invalid limit_area: expecting one of {}, got "
"{}.".format(valid_limit_areas, limit_area)
f"Invalid limit_area: expecting one of {valid_limit_areas}, got "
f"{limit_area}."
)

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

Expand Down Expand Up @@ -375,8 +369,7 @@ def _interpolate_scipy_wrapper(
# GH #10633, #24014
if isna(order) or (order <= 0):
raise ValueError(
"order needs to be specified and greater than 0; "
"got order: {}".format(order)
f"order needs to be specified and greater than 0; got order: {order}"
)
terp = interpolate.UnivariateSpline(x, y, k=order, **kwargs)
new_y = terp(new_x)
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,9 +1301,7 @@ def _ensure_numeric(x):
x = complex(x)
except ValueError:
# e.g. "foo"
raise TypeError(
"Could not convert {value!s} to numeric".format(value=x)
)
raise TypeError(f"Could not convert {x} to numeric")
return x


Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/indexes/datetimes/test_partial_slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_partial_slicing_dataframe(self):
result = df["a"][ts_string]
assert isinstance(result, np.int64)
assert result == expected
msg = r"^'{}'$".format(ts_string)
msg = fr"^'{ts_string}'$"
with pytest.raises(KeyError, match=msg):
df[ts_string]

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

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