diff --git a/pandas/tests/indexes/interval/test_setops.py b/pandas/tests/indexes/interval/test_setops.py index 3246ac6bafde9..d9359d717de1d 100644 --- a/pandas/tests/indexes/interval/test_setops.py +++ b/pandas/tests/indexes/interval/test_setops.py @@ -180,8 +180,8 @@ def test_set_incompatible_types(self, closed, op_name, sort): # GH 19016: incompatible dtypes other = interval_range(Timestamp("20180101"), periods=9, closed=closed) msg = ( - "can only do {op} between two IntervalIndex objects that have " + f"can only do {op_name} between two IntervalIndex objects that have " "compatible dtypes" - ).format(op=op_name) + ) with pytest.raises(TypeError, match=msg): set_op(other, sort=sort) diff --git a/pandas/tests/indexes/multi/test_compat.py b/pandas/tests/indexes/multi/test_compat.py index 9a76f0623eb31..ef549beccda5d 100644 --- a/pandas/tests/indexes/multi/test_compat.py +++ b/pandas/tests/indexes/multi/test_compat.py @@ -29,7 +29,7 @@ def test_numeric_compat(idx): @pytest.mark.parametrize("method", ["all", "any"]) def test_logical_compat(idx, method): - msg = "cannot perform {method}".format(method=method) + msg = f"cannot perform {method}" with pytest.raises(TypeError, match=msg): getattr(idx, method)() diff --git a/pandas/tests/indexes/period/test_constructors.py b/pandas/tests/indexes/period/test_constructors.py index fcbadce3d63b1..418f53591b913 100644 --- a/pandas/tests/indexes/period/test_constructors.py +++ b/pandas/tests/indexes/period/test_constructors.py @@ -364,7 +364,7 @@ def test_constructor_year_and_quarter(self): year = pd.Series([2001, 2002, 2003]) quarter = year - 2000 idx = PeriodIndex(year=year, quarter=quarter) - strs = ["{t[0]:d}Q{t[1]:d}".format(t=t) for t in zip(quarter, year)] + strs = [f"{t[0]:d}Q{t[1]:d}" for t in zip(quarter, year)] lops = list(map(Period, strs)) p = PeriodIndex(lops) tm.assert_index_equal(p, idx) diff --git a/pandas/tests/indexes/timedeltas/test_constructors.py b/pandas/tests/indexes/timedeltas/test_constructors.py index 0de10b5d82171..8e54561df1624 100644 --- a/pandas/tests/indexes/timedeltas/test_constructors.py +++ b/pandas/tests/indexes/timedeltas/test_constructors.py @@ -155,7 +155,7 @@ def test_constructor(self): def test_constructor_iso(self): # GH #21877 expected = timedelta_range("1s", periods=9, freq="s") - durations = ["P0DT0H0M{}S".format(i) for i in range(1, 10)] + durations = [f"P0DT0H0M{i}S" for i in range(1, 10)] result = to_timedelta(durations) tm.assert_index_equal(result, expected) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index f783c3516e357..80a4d81b20a13 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -53,8 +53,8 @@ def test_scalar_error(self, index_func): s.iloc[3.0] msg = ( - "cannot do positional indexing on {klass} with these " - r"indexers \[3\.0\] of type float".format(klass=type(i).__name__) + fr"cannot do positional indexing on {type(i).__name__} with these " + r"indexers \[3\.0\] of type float" ) with pytest.raises(TypeError, match=msg): s.iloc[3.0] = 0 @@ -95,10 +95,10 @@ def test_scalar_non_numeric(self, index_func): error = TypeError msg = ( r"cannot do (label|positional) indexing " - r"on {klass} with these indexers \[3\.0\] of " + fr"on {type(i).__name__} with these indexers \[3\.0\] of " r"type float|" "Cannot index by location index with a " - "non-integer key".format(klass=type(i).__name__) + "non-integer key" ) with pytest.raises(error, match=msg): idxr(s)[3.0] @@ -116,8 +116,8 @@ def test_scalar_non_numeric(self, index_func): error = TypeError msg = ( r"cannot do (label|positional) indexing " - r"on {klass} with these indexers \[3\.0\] of " - r"type float".format(klass=type(i).__name__) + fr"on {type(i).__name__} with these indexers \[3\.0\] of " + "type float" ) with pytest.raises(error, match=msg): s.loc[3.0] @@ -128,8 +128,8 @@ def test_scalar_non_numeric(self, index_func): # setting with a float fails with iloc msg = ( r"cannot do (label|positional) indexing " - r"on {klass} with these indexers \[3\.0\] of " - r"type float".format(klass=type(i).__name__) + fr"on {type(i).__name__} with these indexers \[3\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s.iloc[3.0] = 0 @@ -165,8 +165,8 @@ def test_scalar_non_numeric(self, index_func): s[3] msg = ( r"cannot do (label|positional) indexing " - r"on {klass} with these indexers \[3\.0\] of " - r"type float".format(klass=type(i).__name__) + fr"on {type(i).__name__} with these indexers \[3\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s[3.0] @@ -181,12 +181,10 @@ def test_scalar_with_mixed(self): for idxr in [lambda x: x, lambda x: x.iloc]: msg = ( - r"cannot do label indexing " - r"on {klass} with these indexers \[1\.0\] of " + "cannot do label indexing " + fr"on {Index.__name__} with these indexers \[1\.0\] of " r"type float|" - "Cannot index by location index with a non-integer key".format( - klass=Index.__name__ - ) + "Cannot index by location index with a non-integer key" ) with pytest.raises(TypeError, match=msg): idxr(s2)[1.0] @@ -203,9 +201,9 @@ def test_scalar_with_mixed(self): for idxr in [lambda x: x]: msg = ( - r"cannot do label indexing " - r"on {klass} with these indexers \[1\.0\] of " - r"type float".format(klass=Index.__name__) + "cannot do label indexing " + fr"on {Index.__name__} with these indexers \[1\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): idxr(s3)[1.0] @@ -321,9 +319,9 @@ def test_scalar_float(self): s.iloc[3.0] msg = ( - r"cannot do positional indexing " - r"on {klass} with these indexers \[3\.0\] of " - r"type float".format(klass=Float64Index.__name__) + "cannot do positional indexing " + fr"on {Float64Index.__name__} with these indexers \[3\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s2.iloc[3.0] = 0 @@ -355,8 +353,8 @@ def test_slice_non_numeric(self, index_func): msg = ( "cannot do positional indexing " - r"on {klass} with these indexers \[(3|4)\.0\] of " - "type float".format(klass=type(index).__name__) + fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s.iloc[l] @@ -365,9 +363,9 @@ def test_slice_non_numeric(self, index_func): msg = ( "cannot do (slice|positional) indexing " - r"on {klass} with these indexers " + fr"on {type(index).__name__} with these indexers " r"\[(3|4)(\.0)?\] " - r"of type (float|int)".format(klass=type(index).__name__) + r"of type (float|int)" ) with pytest.raises(TypeError, match=msg): idxr(s)[l] @@ -377,8 +375,8 @@ def test_slice_non_numeric(self, index_func): msg = ( "cannot do positional indexing " - r"on {klass} with these indexers \[(3|4)\.0\] of " - "type float".format(klass=type(index).__name__) + fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s.iloc[l] = 0 @@ -386,9 +384,9 @@ def test_slice_non_numeric(self, index_func): for idxr in [lambda x: x.loc, lambda x: x.iloc, lambda x: x]: msg = ( "cannot do (slice|positional) indexing " - r"on {klass} with these indexers " + fr"on {type(index).__name__} with these indexers " r"\[(3|4)(\.0)?\] " - r"of type (float|int)".format(klass=type(index).__name__) + r"of type (float|int)" ) with pytest.raises(TypeError, match=msg): idxr(s)[l] = 0 @@ -427,8 +425,8 @@ def test_slice_integer(self): # positional indexing msg = ( "cannot do slice indexing " - r"on {klass} with these indexers \[(3|4)\.0\] of " - "type float".format(klass=type(index).__name__) + fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s[l] @@ -451,8 +449,8 @@ def test_slice_integer(self): # positional indexing msg = ( "cannot do slice indexing " - r"on {klass} with these indexers \[-6\.0\] of " - "type float".format(klass=type(index).__name__) + fr"on {type(index).__name__} with these indexers \[-6\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s[slice(-6.0, 6.0)] @@ -477,8 +475,8 @@ def test_slice_integer(self): # positional indexing msg = ( "cannot do slice indexing " - r"on {klass} with these indexers \[(2|3)\.5\] of " - "type float".format(klass=type(index).__name__) + fr"on {type(index).__name__} with these indexers \[(2|3)\.5\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s[l] @@ -495,8 +493,8 @@ def test_slice_integer(self): # positional indexing msg = ( "cannot do slice indexing " - r"on {klass} with these indexers \[(3|4)\.0\] of " - "type float".format(klass=type(index).__name__) + fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s[l] = 0 @@ -518,8 +516,8 @@ def test_integer_positional_indexing(self): klass = RangeIndex msg = ( "cannot do (slice|positional) indexing " - r"on {klass} with these indexers \[(2|4)\.0\] of " - "type float".format(klass=klass.__name__) + fr"on {klass.__name__} with these indexers \[(2|4)\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): idxr(s)[l] @@ -546,8 +544,8 @@ def f(idxr): # positional indexing msg = ( "cannot do slice indexing " - r"on {klass} with these indexers \[(0|1)\.0\] of " - "type float".format(klass=type(index).__name__) + fr"on {type(index).__name__} with these indexers \[(0|1)\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s[l] @@ -561,8 +559,8 @@ def f(idxr): # positional indexing msg = ( "cannot do slice indexing " - r"on {klass} with these indexers \[-10\.0\] of " - "type float".format(klass=type(index).__name__) + fr"on {type(index).__name__} with these indexers \[-10\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s[slice(-10.0, 10.0)] @@ -580,8 +578,8 @@ def f(idxr): # positional indexing msg = ( "cannot do slice indexing " - r"on {klass} with these indexers \[0\.5\] of " - "type float".format(klass=type(index).__name__) + fr"on {type(index).__name__} with these indexers \[0\.5\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s[l] @@ -597,8 +595,8 @@ def f(idxr): # positional indexing msg = ( "cannot do slice indexing " - r"on {klass} with these indexers \[(3|4)\.0\] of " - "type float".format(klass=type(index).__name__) + fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of " + "type float" ) with pytest.raises(TypeError, match=msg): s[l] = 0