Skip to content

Commit bfcfaae

Browse files
authored
CLN: 29547 replace old string formatting 5 (#31967)
1 parent fa2aa9f commit bfcfaae

File tree

10 files changed

+47
-68
lines changed

10 files changed

+47
-68
lines changed

pandas/tests/io/parser/test_c_parser_only.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_precise_conversion(c_parser_only):
158158
# test numbers between 1 and 2
159159
for num in np.linspace(1.0, 2.0, num=500):
160160
# 25 decimal digits of precision
161-
text = "a\n{0:.25}".format(num)
161+
text = f"a\n{num:.25}"
162162

163163
normal_val = float(parser.read_csv(StringIO(text))["a"][0])
164164
precise_val = float(
@@ -170,7 +170,7 @@ def test_precise_conversion(c_parser_only):
170170
actual_val = Decimal(text[2:])
171171

172172
def error(val):
173-
return abs(Decimal("{0:.100}".format(val)) - actual_val)
173+
return abs(Decimal(f"{val:.100}") - actual_val)
174174

175175
normal_errors.append(error(normal_val))
176176
precise_errors.append(error(precise_val))
@@ -299,9 +299,7 @@ def test_grow_boundary_at_cap(c_parser_only):
299299

300300
def test_empty_header_read(count):
301301
s = StringIO("," * count)
302-
expected = DataFrame(
303-
columns=["Unnamed: {i}".format(i=i) for i in range(count + 1)]
304-
)
302+
expected = DataFrame(columns=[f"Unnamed: {i}" for i in range(count + 1)])
305303
df = parser.read_csv(s)
306304
tm.assert_frame_equal(df, expected)
307305

@@ -489,7 +487,7 @@ def test_comment_whitespace_delimited(c_parser_only, capsys):
489487
captured = capsys.readouterr()
490488
# skipped lines 2, 3, 4, 9
491489
for line_num in (2, 3, 4, 9):
492-
assert "Skipping line {}".format(line_num) in captured.err
490+
assert f"Skipping line {line_num}" in captured.err
493491
expected = DataFrame([[1, 2], [5, 2], [6, 2], [7, np.nan], [8, np.nan]])
494492
tm.assert_frame_equal(df, expected)
495493

pandas/tests/io/parser/test_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ def test_nonexistent_path(all_parsers):
957957
# gh-14086: raise more helpful FileNotFoundError
958958
# GH#29233 "File foo" instead of "File b'foo'"
959959
parser = all_parsers
960-
path = "{}.csv".format(tm.rands(10))
960+
path = f"{tm.rands(10)}.csv"
961961

962962
msg = f"File {path} does not exist" if parser.engine == "c" else r"\[Errno 2\]"
963963
with pytest.raises(FileNotFoundError, match=msg) as e:
@@ -1872,7 +1872,7 @@ def test_internal_eof_byte_to_file(all_parsers):
18721872
parser = all_parsers
18731873
data = b'c1,c2\r\n"test \x1a test", test\r\n'
18741874
expected = DataFrame([["test \x1a test", " test"]], columns=["c1", "c2"])
1875-
path = "__{}__.csv".format(tm.rands(10))
1875+
path = f"__{tm.rands(10)}__.csv"
18761876

18771877
with tm.ensure_clean(path) as path:
18781878
with open(path, "wb") as f:

pandas/tests/io/parser/test_compression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def test_invalid_compression(all_parsers, invalid_compression):
145145
parser = all_parsers
146146
compress_kwargs = dict(compression=invalid_compression)
147147

148-
msg = "Unrecognized compression type: {compression}".format(**compress_kwargs)
148+
msg = f"Unrecognized compression type: {invalid_compression}"
149149

150150
with pytest.raises(ValueError, match=msg):
151151
parser.read_csv("test_file.zip", **compress_kwargs)

pandas/tests/io/parser/test_encoding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_utf16_bom_skiprows(all_parsers, sep, encoding):
4545
4,5,6""".replace(
4646
",", sep
4747
)
48-
path = "__{}__.csv".format(tm.rands(10))
48+
path = f"__{tm.rands(10)}__.csv"
4949
kwargs = dict(sep=sep, skiprows=2)
5050
utf8 = "utf-8"
5151

pandas/tests/io/parser/test_multi_thread.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ def test_multi_thread_string_io_read_csv(all_parsers):
4141
num_files = 100
4242

4343
bytes_to_df = [
44-
"\n".join(
45-
["{i:d},{i:d},{i:d}".format(i=i) for i in range(max_row_range)]
46-
).encode()
44+
"\n".join([f"{i:d},{i:d},{i:d}" for i in range(max_row_range)]).encode()
4745
for _ in range(num_files)
4846
]
4947
files = [BytesIO(b) for b in bytes_to_df]

pandas/tests/io/parser/test_na_values.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ def f(i, v):
111111
elif i > 0:
112112
buf = "".join([","] * i)
113113

114-
buf = "{0}{1}".format(buf, v)
114+
buf = f"{buf}{v}"
115115

116116
if i < nv - 1:
117-
buf = "{0}{1}".format(buf, "".join([","] * (nv - i - 1)))
117+
joined = "".join([","] * (nv - i - 1))
118+
buf = f"{buf}{joined}"
118119

119120
return buf
120121

pandas/tests/io/parser/test_parse_dates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ def test_bad_date_parse(all_parsers, cache_dates, value):
11011101
# if we have an invalid date make sure that we handle this with
11021102
# and w/o the cache properly
11031103
parser = all_parsers
1104-
s = StringIO(("{value},\n".format(value=value)) * 50000)
1104+
s = StringIO((f"{value},\n") * 50000)
11051105

11061106
parser.read_csv(
11071107
s,

pandas/tests/io/parser/test_read_fwf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def test_fwf_regression():
260260
# Turns out "T060" is parsable as a datetime slice!
261261
tz_list = [1, 10, 20, 30, 60, 80, 100]
262262
widths = [16] + [8] * len(tz_list)
263-
names = ["SST"] + ["T{z:03d}".format(z=z) for z in tz_list[1:]]
263+
names = ["SST"] + [f"T{z:03d}" for z in tz_list[1:]]
264264

265265
data = """ 2009164202000 9.5403 9.4105 8.6571 7.8372 6.0612 5.8843 5.5192
266266
2009164203000 9.5435 9.2010 8.6167 7.8176 6.0804 5.8728 5.4869

pandas/tests/io/pytables/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@pytest.fixture
77
def setup_path():
88
"""Fixture for setup path"""
9-
return "tmp.__{}__.h5".format(tm.rands(10))
9+
return f"tmp.__{tm.rands(10)}__.h5"
1010

1111

1212
@pytest.fixture(scope="module", autouse=True)

0 commit comments

Comments
 (0)