Skip to content

CLN: 29547 replace old string formatting 3 #31945

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
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
4 changes: 2 additions & 2 deletions pandas/tests/indexes/interval/test_setops.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion pandas/tests/indexes/multi/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)()
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/period/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/timedeltas/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
92 changes: 45 additions & 47 deletions pandas/tests/indexing/test_floats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -377,18 +375,18 @@ 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

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
Expand Down Expand Up @@ -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]
Expand All @@ -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)]
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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)]
Expand All @@ -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]
Expand All @@ -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
Expand Down