Skip to content

Commit cc2e1c1

Browse files
author
Matteo Felici
committed
CLN: GH29547 change string formatting with f-strings - revert useless changes
1 parent 3fa510b commit cc2e1c1

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

pandas/tests/io/test_html.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,7 @@ def test_tfoot_read(self):
507507
Make sure that read_html reads tfoot, containing td or th.
508508
Ignores empty tfoot
509509
"""
510-
data_template = (
511-
lambda footer: f"""<table>
510+
data_template = """<table>
512511
<thead>
513512
<tr>
514513
<th>A</th>
@@ -525,16 +524,15 @@ def test_tfoot_read(self):
525524
{footer}
526525
</tfoot>
527526
</table>"""
528-
)
529527

530528
expected1 = DataFrame(data=[["bodyA", "bodyB"]], columns=["A", "B"])
531529

532530
expected2 = DataFrame(
533531
data=[["bodyA", "bodyB"], ["footA", "footB"]], columns=["A", "B"]
534532
)
535533

536-
data1 = data_template(footer="")
537-
data2 = data_template(footer="<tr><td>footA</td><th>footB</th></tr>")
534+
data1 = data_template.format(footer="")
535+
data2 = data_template.format(footer="<tr><td>footA</td><th>footB</th></tr>")
538536

539537
result1 = self.read_html(data1)[0]
540538
result2 = self.read_html(data2)[0]

pandas/tests/reshape/test_melt.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -313,30 +313,32 @@ def test_melt_missing_columns_raises(self):
313313
df = pd.DataFrame(np.random.randn(5, 4), columns=list("abcd"))
314314

315315
# Try to melt with missing `value_vars` column name
316-
msg = (
317-
lambda Var, Col: f"The following '{Var}' are not present in "
318-
f"the DataFrame: {Col}"
319-
)
320-
with pytest.raises(KeyError, match=msg(Var="value_vars", Col="\\['C'\\]")):
316+
msg = "The following '{Var}' are not present in the DataFrame: {Col}"
317+
with pytest.raises(
318+
KeyError, match=msg.format(Var="value_vars", Col="\\['C'\\]")
319+
):
321320
df.melt(["a", "b"], ["C", "d"])
322321

323322
# Try to melt with missing `id_vars` column name
324-
with pytest.raises(KeyError, match=msg(Var="id_vars", Col="\\['A'\\]")):
323+
with pytest.raises(KeyError, match=msg.format(Var="id_vars", Col="\\['A'\\]")):
325324
df.melt(["A", "b"], ["c", "d"])
326325

327326
# Multiple missing
328327
with pytest.raises(
329-
KeyError, match=msg(Var="id_vars", Col="\\['not_here', 'or_there'\\]"),
328+
KeyError,
329+
match=msg.format(Var="id_vars", Col="\\['not_here', 'or_there'\\]"),
330330
):
331331
df.melt(["a", "b", "not_here", "or_there"], ["c", "d"])
332332

333333
# Multiindex melt fails if column is missing from multilevel melt
334334
multi = df.copy()
335335
multi.columns = [list("ABCD"), list("abcd")]
336-
with pytest.raises(KeyError, match=msg(Var="id_vars", Col="\\['E'\\]")):
336+
with pytest.raises(KeyError, match=msg.format(Var="id_vars", Col="\\['E'\\]")):
337337
multi.melt([("E", "a")], [("B", "b")])
338338
# Multiindex fails if column is missing from single level melt
339-
with pytest.raises(KeyError, match=msg(Var="value_vars", Col="\\['F'\\]")):
339+
with pytest.raises(
340+
KeyError, match=msg.format(Var="value_vars", Col="\\['F'\\]")
341+
):
340342
multi.melt(["A"], ["F"], col_level=0)
341343

342344
def test_melt_mixed_int_str_id_vars(self):

pandas/tests/scalar/timedelta/test_timedelta.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ def check(value):
8383
assert rng.microseconds == 0
8484
assert rng.nanoseconds == 0
8585

86-
msg = lambda x: f"'Timedelta' object has no attribute '{x}'"
87-
with pytest.raises(AttributeError, match=msg("hours")):
86+
msg = "'Timedelta' object has no attribute '{}'"
87+
with pytest.raises(AttributeError, match=msg.format("hours")):
8888
rng.hours
89-
with pytest.raises(AttributeError, match=msg("minutes")):
89+
with pytest.raises(AttributeError, match=msg.format("minutes")):
9090
rng.minutes
91-
with pytest.raises(AttributeError, match=msg("milliseconds")):
91+
with pytest.raises(AttributeError, match=msg.format("milliseconds")):
9292
rng.milliseconds
9393

9494
# GH 10050
@@ -109,12 +109,12 @@ def check(value):
109109
assert rng.seconds == 10 * 3600 + 11 * 60 + 12
110110
assert rng.microseconds == 100 * 1000 + 123
111111
assert rng.nanoseconds == 456
112-
msg = lambda x: f"'Timedelta' object has no attribute '{x}'"
113-
with pytest.raises(AttributeError, match=msg("hours")):
112+
msg = "'Timedelta' object has no attribute '{}'"
113+
with pytest.raises(AttributeError, match=msg.format("hours")):
114114
rng.hours
115-
with pytest.raises(AttributeError, match=msg("minutes")):
115+
with pytest.raises(AttributeError, match=msg.format("minutes")):
116116
rng.minutes
117-
with pytest.raises(AttributeError, match=msg("milliseconds")):
117+
with pytest.raises(AttributeError, match=msg.format("milliseconds")):
118118
rng.milliseconds
119119

120120
# components

0 commit comments

Comments
 (0)