diff --git a/pandas/core/missing.py b/pandas/core/missing.py index 5b9e37bd54bad..b30a7a24f3495 100644 --- a/pandas/core/missing.py +++ b/pandas/core/missing.py @@ -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 @@ -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 @@ -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}'." ) @@ -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 @@ -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 @@ -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) diff --git a/pandas/core/nanops.py b/pandas/core/nanops.py index 8de955e5ff2cf..f27e3d4527921 100644 --- a/pandas/core/nanops.py +++ b/pandas/core/nanops.py @@ -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 diff --git a/pandas/tests/indexes/datetimes/test_partial_slicing.py b/pandas/tests/indexes/datetimes/test_partial_slicing.py index 51aeb40744c3a..8d5aa64a49cf2 100644 --- a/pandas/tests/indexes/datetimes/test_partial_slicing.py +++ b/pandas/tests/indexes/datetimes/test_partial_slicing.py @@ -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] @@ -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] @@ -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):