Skip to content

CLN: 29547 replace old string formatting 5 #31967

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
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 4 additions & 6 deletions pandas/tests/io/parser/test_c_parser_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_precise_conversion(c_parser_only):
# test numbers between 1 and 2
for num in np.linspace(1.0, 2.0, num=500):
# 25 decimal digits of precision
text = "a\n{0:.25}".format(num)
text = f"a\n{num:.25}"

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

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

normal_errors.append(error(normal_val))
precise_errors.append(error(precise_val))
Expand Down Expand Up @@ -299,9 +299,7 @@ def test_grow_boundary_at_cap(c_parser_only):

def test_empty_header_read(count):
s = StringIO("," * count)
expected = DataFrame(
columns=["Unnamed: {i}".format(i=i) for i in range(count + 1)]
)
expected = DataFrame(columns=[f"Unnamed: {i}" for i in range(count + 1)])
df = parser.read_csv(s)
tm.assert_frame_equal(df, expected)

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

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/parser/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ def test_nonexistent_path(all_parsers):
# gh-14086: raise more helpful FileNotFoundError
# GH#29233 "File foo" instead of "File b'foo'"
parser = all_parsers
path = "{}.csv".format(tm.rands(10))
path = f"{tm.rands(10)}.csv"

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

with tm.ensure_clean(path) as path:
with open(path, "wb") as f:
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/parser/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_invalid_compression(all_parsers, invalid_compression):
parser = all_parsers
compress_kwargs = dict(compression=invalid_compression)

msg = "Unrecognized compression type: {compression}".format(**compress_kwargs)
msg = f"Unrecognized compression type: {compress_kwargs['compression']}"

with pytest.raises(ValueError, match=msg):
parser.read_csv("test_file.zip", **compress_kwargs)
2 changes: 1 addition & 1 deletion pandas/tests/io/parser/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_utf16_bom_skiprows(all_parsers, sep, encoding):
4,5,6""".replace(
",", sep
)
path = "__{}__.csv".format(tm.rands(10))
path = f"__{tm.rands(10)}__.csv"
kwargs = dict(sep=sep, skiprows=2)
utf8 = "utf-8"

Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/io/parser/test_multi_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def test_multi_thread_string_io_read_csv(all_parsers):
num_files = 100

bytes_to_df = [
"\n".join(
["{i:d},{i:d},{i:d}".format(i=i) for i in range(max_row_range)]
).encode()
"\n".join([f"{i:d},{i:d},{i:d}" for i in range(max_row_range)]).encode()
for _ in range(num_files)
]
files = [BytesIO(b) for b in bytes_to_df]
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/parser/test_na_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ def f(i, v):
elif i > 0:
buf = "".join([","] * i)

buf = "{0}{1}".format(buf, v)
buf = f"{buf}{v}"

if i < nv - 1:
buf = "{0}{1}".format(buf, "".join([","] * (nv - i - 1)))
buf = f"{buf}{''.join([','] * (nv - i - 1))}"

return buf

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/parser/test_parse_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ def test_bad_date_parse(all_parsers, cache_dates, value):
# if we have an invalid date make sure that we handle this with
# and w/o the cache properly
parser = all_parsers
s = StringIO(("{value},\n".format(value=value)) * 50000)
s = StringIO((f"{value},\n") * 50000)

parser.read_csv(
s,
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/parser/test_read_fwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def test_fwf_regression():
# Turns out "T060" is parsable as a datetime slice!
tz_list = [1, 10, 20, 30, 60, 80, 100]
widths = [16] + [8] * len(tz_list)
names = ["SST"] + ["T{z:03d}".format(z=z) for z in tz_list[1:]]
names = ["SST"] + [f"T{z:03d}" for z in tz_list[1:]]

data = """ 2009164202000 9.5403 9.4105 8.6571 7.8372 6.0612 5.8843 5.5192
2009164203000 9.5435 9.2010 8.6167 7.8176 6.0804 5.8728 5.4869
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/io/pytables/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@pytest.fixture
def setup_path():
"""Fixture for setup path"""
return "tmp.__{}__.h5".format(tm.rands(10))
return f"tmp.__{tm.rands(10)}__.h5"


@pytest.fixture(scope="module", autouse=True)
Expand Down
Loading