Skip to content

Commit 6d30046

Browse files
authored
CLN: 29547 replace old string formatting 6 (#31980)
1 parent 8425c26 commit 6d30046

File tree

11 files changed

+36
-49
lines changed

11 files changed

+36
-49
lines changed

pandas/tests/indexing/test_floats.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_scalar_error(self, index_func):
5353
s.iloc[3.0]
5454

5555
msg = (
56-
fr"cannot do positional indexing on {type(i).__name__} with these "
56+
f"cannot do positional indexing on {type(i).__name__} with these "
5757
r"indexers \[3\.0\] of type float"
5858
)
5959
with pytest.raises(TypeError, match=msg):

pandas/tests/io/pytables/test_timezones.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ def _compare_with_tz(a, b):
2424
a_e = a.loc[i, c]
2525
b_e = b.loc[i, c]
2626
if not (a_e == b_e and a_e.tz == b_e.tz):
27-
raise AssertionError(
28-
"invalid tz comparison [{a_e}] [{b_e}]".format(a_e=a_e, b_e=b_e)
29-
)
27+
raise AssertionError(f"invalid tz comparison [{a_e}] [{b_e}]")
3028

3129

3230
def test_append_with_timezones_dateutil(setup_path):

pandas/tests/io/test_html.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def html_encoding_file(request, datapath):
4040
def assert_framelist_equal(list1, list2, *args, **kwargs):
4141
assert len(list1) == len(list2), (
4242
"lists are not of equal size "
43-
"len(list1) == {0}, "
44-
"len(list2) == {1}".format(len(list1), len(list2))
43+
f"len(list1) == {len(list1)}, "
44+
f"len(list2) == {len(list2)}"
4545
)
4646
msg = "not all list elements are DataFrames"
4747
both_frames = all(

pandas/tests/io/test_stata.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,7 @@ def test_invalid_file_not_written(self, version):
17151715
"'ascii' codec can't decode byte 0xef in position 14: "
17161716
r"ordinal not in range\(128\)"
17171717
)
1718-
with pytest.raises(UnicodeEncodeError, match=r"{}|{}".format(msg1, msg2)):
1718+
with pytest.raises(UnicodeEncodeError, match=f"{msg1}|{msg2}"):
17191719
with tm.assert_produces_warning(ResourceWarning):
17201720
df.to_stata(path)
17211721

pandas/tests/resample/test_period_index.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ def test_selection(self, index, freq, kind, kwargs):
9696
def test_annual_upsample_cases(
9797
self, targ, conv, meth, month, simple_period_range_series
9898
):
99-
ts = simple_period_range_series(
100-
"1/1/1990", "12/31/1991", freq="A-{month}".format(month=month)
101-
)
99+
ts = simple_period_range_series("1/1/1990", "12/31/1991", freq=f"A-{month}")
102100

103101
result = getattr(ts.resample(targ, convention=conv), meth)()
104102
expected = result.to_timestamp(targ, how=conv)
@@ -130,9 +128,9 @@ def test_not_subperiod(self, simple_period_range_series, rule, expected_error_ms
130128
# These are incompatible period rules for resampling
131129
ts = simple_period_range_series("1/1/1990", "6/30/1995", freq="w-wed")
132130
msg = (
133-
"Frequency <Week: weekday=2> cannot be resampled to {}, as they "
134-
"are not sub or super periods"
135-
).format(expected_error_msg)
131+
"Frequency <Week: weekday=2> cannot be resampled to "
132+
f"{expected_error_msg}, as they are not sub or super periods"
133+
)
136134
with pytest.raises(IncompatibleFrequency, match=msg):
137135
ts.resample(rule).mean()
138136

@@ -176,7 +174,7 @@ def test_annual_upsample(self, simple_period_range_series):
176174
def test_quarterly_upsample(
177175
self, month, target, convention, simple_period_range_series
178176
):
179-
freq = "Q-{month}".format(month=month)
177+
freq = f"Q-{month}"
180178
ts = simple_period_range_series("1/1/1990", "12/31/1995", freq=freq)
181179
result = ts.resample(target, convention=convention).ffill()
182180
expected = result.to_timestamp(target, how=convention)
@@ -351,7 +349,7 @@ def test_fill_method_and_how_upsample(self):
351349
@pytest.mark.parametrize("target", ["D", "B"])
352350
@pytest.mark.parametrize("convention", ["start", "end"])
353351
def test_weekly_upsample(self, day, target, convention, simple_period_range_series):
354-
freq = "W-{day}".format(day=day)
352+
freq = f"W-{day}"
355353
ts = simple_period_range_series("1/1/1990", "12/31/1995", freq=freq)
356354
result = ts.resample(target, convention=convention).ffill()
357355
expected = result.to_timestamp(target, how=convention)
@@ -367,16 +365,14 @@ def test_resample_to_timestamps(self, simple_period_range_series):
367365

368366
def test_resample_to_quarterly(self, simple_period_range_series):
369367
for month in MONTHS:
370-
ts = simple_period_range_series(
371-
"1990", "1992", freq="A-{month}".format(month=month)
372-
)
373-
quar_ts = ts.resample("Q-{month}".format(month=month)).ffill()
368+
ts = simple_period_range_series("1990", "1992", freq=f"A-{month}")
369+
quar_ts = ts.resample(f"Q-{month}").ffill()
374370

375371
stamps = ts.to_timestamp("D", how="start")
376372
qdates = period_range(
377373
ts.index[0].asfreq("D", "start"),
378374
ts.index[-1].asfreq("D", "end"),
379-
freq="Q-{month}".format(month=month),
375+
freq=f"Q-{month}",
380376
)
381377

382378
expected = stamps.reindex(qdates.to_timestamp("D", "s"), method="ffill")

pandas/tests/reshape/merge/test_join.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,9 @@ def test_join_on_fails_with_wrong_object_type(self, wrong_type):
262262
# Edited test to remove the Series object from test parameters
263263

264264
df = DataFrame({"a": [1, 1]})
265-
msg = "Can only merge Series or DataFrame objects, a {} was passed".format(
266-
str(type(wrong_type))
265+
msg = (
266+
"Can only merge Series or DataFrame objects, "
267+
f"a {type(wrong_type)} was passed"
267268
)
268269
with pytest.raises(TypeError, match=msg):
269270
merge(wrong_type, df, left_on="a", right_on="a")
@@ -812,9 +813,7 @@ def _check_join(left, right, result, join_col, how="left", lsuffix="_x", rsuffix
812813
except KeyError:
813814
if how in ("left", "inner"):
814815
raise AssertionError(
815-
"key {group_key!s} should not have been in the join".format(
816-
group_key=group_key
817-
)
816+
f"key {group_key} should not have been in the join"
818817
)
819818

820819
_assert_all_na(l_joined, left.columns, join_col)
@@ -826,9 +825,7 @@ def _check_join(left, right, result, join_col, how="left", lsuffix="_x", rsuffix
826825
except KeyError:
827826
if how in ("right", "inner"):
828827
raise AssertionError(
829-
"key {group_key!s} should not have been in the join".format(
830-
group_key=group_key
831-
)
828+
f"key {group_key} should not have been in the join"
832829
)
833830

834831
_assert_all_na(r_joined, right.columns, join_col)

pandas/tests/reshape/merge/test_merge.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ def test_other_timedelta_unit(self, unit):
710710
df1 = pd.DataFrame({"entity_id": [101, 102]})
711711
s = pd.Series([None, None], index=[101, 102], name="days")
712712

713-
dtype = "m8[{}]".format(unit)
713+
dtype = f"m8[{unit}]"
714714
df2 = s.astype(dtype).to_frame("days")
715715
assert df2["days"].dtype == "m8[ns]"
716716

@@ -1012,9 +1012,9 @@ def test_indicator(self):
10121012

10131013
msg = (
10141014
"Cannot use `indicator=True` option when data contains a "
1015-
"column named {}|"
1015+
f"column named {i}|"
10161016
"Cannot use name of an existing column for indicator column"
1017-
).format(i)
1017+
)
10181018
with pytest.raises(ValueError, match=msg):
10191019
merge(df1, df_badcolumn, on="col1", how="outer", indicator=True)
10201020
with pytest.raises(ValueError, match=msg):
@@ -1555,23 +1555,19 @@ def test_merge_incompat_dtypes_error(self, df1_vals, df2_vals):
15551555
df2 = DataFrame({"A": df2_vals})
15561556

15571557
msg = (
1558-
"You are trying to merge on {lk_dtype} and "
1559-
"{rk_dtype} columns. If you wish to proceed "
1560-
"you should use pd.concat".format(
1561-
lk_dtype=df1["A"].dtype, rk_dtype=df2["A"].dtype
1562-
)
1558+
f"You are trying to merge on {df1['A'].dtype} and "
1559+
f"{df2['A'].dtype} columns. If you wish to proceed "
1560+
"you should use pd.concat"
15631561
)
15641562
msg = re.escape(msg)
15651563
with pytest.raises(ValueError, match=msg):
15661564
pd.merge(df1, df2, on=["A"])
15671565

15681566
# Check that error still raised when swapping order of dataframes
15691567
msg = (
1570-
"You are trying to merge on {lk_dtype} and "
1571-
"{rk_dtype} columns. If you wish to proceed "
1572-
"you should use pd.concat".format(
1573-
lk_dtype=df2["A"].dtype, rk_dtype=df1["A"].dtype
1574-
)
1568+
f"You are trying to merge on {df2['A'].dtype} and "
1569+
f"{df1['A'].dtype} columns. If you wish to proceed "
1570+
"you should use pd.concat"
15751571
)
15761572
msg = re.escape(msg)
15771573
with pytest.raises(ValueError, match=msg):

pandas/tests/reshape/merge/test_merge_asof.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ def test_merge_groupby_multiple_column_with_categorical_column(self):
11961196
@pytest.mark.parametrize("side", ["left", "right"])
11971197
def test_merge_on_nans(self, func, side):
11981198
# GH 23189
1199-
msg = "Merge keys contain null values on {} side".format(side)
1199+
msg = f"Merge keys contain null values on {side} side"
12001200
nulls = func([1.0, 5.0, np.nan])
12011201
non_nulls = func([1.0, 5.0, 10.0])
12021202
df_null = pd.DataFrame({"a": nulls, "left_val": ["a", "b", "c"]})

pandas/tests/reshape/test_melt.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ def test_pairs(self):
364364
df = DataFrame(data)
365365

366366
spec = {
367-
"visitdt": ["visitdt{i:d}".format(i=i) for i in range(1, 4)],
368-
"wt": ["wt{i:d}".format(i=i) for i in range(1, 4)],
367+
"visitdt": [f"visitdt{i:d}" for i in range(1, 4)],
368+
"wt": [f"wt{i:d}" for i in range(1, 4)],
369369
}
370370
result = lreshape(df, spec)
371371

@@ -557,8 +557,8 @@ def test_pairs(self):
557557
result = lreshape(df, spec, dropna=False, label="foo")
558558

559559
spec = {
560-
"visitdt": ["visitdt{i:d}".format(i=i) for i in range(1, 3)],
561-
"wt": ["wt{i:d}".format(i=i) for i in range(1, 4)],
560+
"visitdt": [f"visitdt{i:d}" for i in range(1, 3)],
561+
"wt": [f"wt{i:d}" for i in range(1, 4)],
562562
}
563563
msg = "All column lists must be same length"
564564
with pytest.raises(ValueError, match=msg):

pandas/tests/reshape/test_pivot.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1161,9 +1161,9 @@ def test_margins_no_values_two_row_two_cols(self):
11611161
def test_pivot_table_with_margins_set_margin_name(self, margin_name):
11621162
# see gh-3335
11631163
msg = (
1164-
r'Conflicting name "{}" in margins|'
1164+
f'Conflicting name "{margin_name}" in margins|'
11651165
"margins_name argument must be a string"
1166-
).format(margin_name)
1166+
)
11671167
with pytest.raises(ValueError, match=msg):
11681168
# multi-index index
11691169
pivot_table(

pandas/tests/scalar/timedelta/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def test_iso_constructor(fmt, exp):
239239
],
240240
)
241241
def test_iso_constructor_raises(fmt):
242-
msg = "Invalid ISO 8601 Duration format - {}".format(fmt)
242+
msg = f"Invalid ISO 8601 Duration format - {fmt}"
243243
with pytest.raises(ValueError, match=msg):
244244
Timedelta(fmt)
245245

0 commit comments

Comments
 (0)