Skip to content

CLN: 29547 replace old string formatting 7 #31986

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
6 changes: 2 additions & 4 deletions pandas/tests/scalar/timestamp/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def test_constructor_nanosecond(self, result):
def test_constructor_invalid_Z0_isostring(self, z):
# GH 8910
with pytest.raises(ValueError):
Timestamp("2014-11-02 01:00{}".format(z))
Timestamp(f"2014-11-02 01:00{z}")

@pytest.mark.parametrize(
"arg",
Expand Down Expand Up @@ -455,9 +455,7 @@ def test_disallow_setting_tz(self, tz):
@pytest.mark.parametrize("offset", ["+0300", "+0200"])
def test_construct_timestamp_near_dst(self, offset):
# GH 20854
expected = Timestamp(
"2016-10-30 03:00:00{}".format(offset), tz="Europe/Helsinki"
)
expected = Timestamp(f"2016-10-30 03:00:00{offset}", tz="Europe/Helsinki")
result = Timestamp(expected).tz_convert("Europe/Helsinki")
assert result == expected

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/scalar/timestamp/test_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class TestTimestampRendering:
)
def test_repr(self, date, freq, tz):
# avoid to match with timezone name
freq_repr = "'{0}'".format(freq)
freq_repr = f"'{freq}'"
if tz.startswith("dateutil"):
tz_repr = tz.replace("dateutil", "")
else:
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/scalar/timestamp/test_unary_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,17 @@ def test_round_int64(self, timestamp, freq):

# test floor
result = dt.floor(freq)
assert result.value % unit == 0, "floor not a {} multiple".format(freq)
assert result.value % unit == 0, f"floor not a {freq} multiple"
assert 0 <= dt.value - result.value < unit, "floor error"

# test ceil
result = dt.ceil(freq)
assert result.value % unit == 0, "ceil not a {} multiple".format(freq)
assert result.value % unit == 0, f"ceil not a {freq} multiple"
assert 0 <= result.value - dt.value < unit, "ceil error"

# test round
result = dt.round(freq)
assert result.value % unit == 0, "round not a {} multiple".format(freq)
assert result.value % unit == 0, f"round not a {freq} multiple"
assert abs(result.value - dt.value) <= unit // 2, "round error"
if unit % 2 == 0 and abs(result.value - dt.value) == unit // 2:
# round half to even
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/methods/test_nlargest.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class TestSeriesNLargestNSmallest:
)
def test_nlargest_error(self, r):
dt = r.dtype
msg = "Cannot use method 'n(larg|small)est' with dtype {dt}".format(dt=dt)
msg = f"Cannot use method 'n(larg|small)est' with dtype {dt}"
args = 2, len(r), 0, -1
methods = r.nlargest, r.nsmallest
for method, arg in product(methods, args):
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ def test_validate_any_all_out_keepdims_raises(self, kwargs, func):
name = func.__name__

msg = (
r"the '{arg}' parameter is not "
r"supported in the pandas "
r"implementation of {fname}\(\)"
).format(arg=param, fname=name)
f"the '{param}' parameter is not "
"supported in the pandas "
fr"implementation of {name}\(\)"
)
with pytest.raises(ValueError, match=msg):
func(s, **kwargs)

Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/series/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ def test_constructor_subclass_dict(self, dict_subclass):

def test_constructor_ordereddict(self):
# GH3283
data = OrderedDict(
("col{i}".format(i=i), np.random.random()) for i in range(12)
)
data = OrderedDict((f"col{i}", np.random.random()) for i in range(12))

series = Series(data)
expected = Series(list(data.values()), list(data.keys()))
Expand Down Expand Up @@ -258,7 +256,7 @@ def get_dir(s):
tm.makeIntIndex(10),
tm.makeFloatIndex(10),
Index([True, False]),
Index(["a{}".format(i) for i in range(101)]),
Index([f"a{i}" for i in range(101)]),
pd.MultiIndex.from_tuples(zip("ABCD", "EFGH")),
pd.MultiIndex.from_tuples(zip([0, 1, 2, 3], "EFGH")),
],
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/series/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def test_astype_categorical_to_other(self):

value = np.random.RandomState(0).randint(0, 10000, 100)
df = DataFrame({"value": value})
labels = ["{0} - {1}".format(i, i + 499) for i in range(0, 10000, 500)]
labels = [f"{i} - {i + 499}" for i in range(0, 10000, 500)]
cat_labels = Categorical(labels, labels)

df = df.sort_values(by=["value"], ascending=True)
Expand Down Expand Up @@ -384,9 +384,9 @@ def test_astype_generic_timestamp_no_frequency(self, dtype):
s = Series(data)

msg = (
r"The '{dtype}' dtype has no unit\. "
r"Please pass in '{dtype}\[ns\]' instead."
).format(dtype=dtype.__name__)
fr"The '{dtype.__name__}' dtype has no unit\. "
fr"Please pass in '{dtype.__name__}\[ns\]' instead."
)
with pytest.raises(ValueError, match=msg):
s.astype(dtype)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_ufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def __eq__(self, other) -> bool:
return type(other) is Thing and self.value == other.value

def __repr__(self) -> str:
return "Thing({})".format(self.value)
return f"Thing({self.value})"

s = pd.Series([Thing(1), Thing(2)])
result = np.add(s, Thing(1))
Expand Down