Skip to content

CLN: 29547 replace old string formatting 2 #31933

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 2 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
4 changes: 2 additions & 2 deletions pandas/tests/frame/test_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,8 @@ def test_inplace_ops_identity2(self, op):
df["a"] = [True, False, True]

df_copy = df.copy()
iop = "__i{}__".format(op)
op = "__{}__".format(op)
iop = f"__i{op}__"
op = f"__{op}__"

# no id change and value is correct
getattr(df, iop)(operand)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/frame/test_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,8 @@ def test_unstack_unused_level(self, cols):
tm.assert_frame_equal(result, expected)

def test_unstack_nan_index(self): # GH7466
cast = lambda val: "{0:1}".format("" if val != val else val)
val_str = lambda val: "" if val != val else val
cast = lambda val: f"{val_str(val):1}"

def verify(df):
mk_list = lambda a: list(a) if isinstance(a, tuple) else [a]
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/frame/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_frame_append_datetime64_col_other_units(self):
ns_dtype = np.dtype("M8[ns]")

for unit in units:
dtype = np.dtype("M8[{unit}]".format(unit=unit))
dtype = np.dtype(f"M8[{unit}]")
vals = np.arange(n, dtype=np.int64).view(dtype)

df = DataFrame({"ints": np.arange(n)}, index=np.arange(n))
Expand All @@ -70,7 +70,7 @@ def test_frame_append_datetime64_col_other_units(self):
df["dates"] = np.arange(n, dtype=np.int64).view(ns_dtype)

for unit in units:
dtype = np.dtype("M8[{unit}]".format(unit=unit))
dtype = np.dtype(f"M8[{unit}]")
vals = np.arange(n, dtype=np.int64).view(dtype)

tmp = df.copy()
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/indexes/datetimes/test_scalar_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,21 @@ def test_round_int64(self, start, index_freq, periods, round_freq):
result = dt.floor(round_freq)
diff = dt.asi8 - result.asi8
mod = result.asi8 % unit
assert (mod == 0).all(), "floor not a {} multiple".format(round_freq)
assert (mod == 0).all(), f"floor not a {round_freq} multiple"
assert (0 <= diff).all() and (diff < unit).all(), "floor error"

# test ceil
result = dt.ceil(round_freq)
diff = result.asi8 - dt.asi8
mod = result.asi8 % unit
assert (mod == 0).all(), "ceil not a {} multiple".format(round_freq)
assert (mod == 0).all(), f"ceil not a {round_freq} multiple"
assert (0 <= diff).all() and (diff < unit).all(), "ceil error"

# test round
result = dt.round(round_freq)
diff = abs(result.asi8 - dt.asi8)
mod = result.asi8 % unit
assert (mod == 0).all(), "round not a {} multiple".format(round_freq)
assert (mod == 0).all(), f"round not a {round_freq} multiple"
assert (diff <= unit // 2).all(), "round error"
if unit % 2 == 0:
assert (
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/datetimes/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def test_to_datetime_format_microsecond(self, cache):
# these are locale dependent
lang, _ = locale.getlocale()
month_abbr = calendar.month_abbr[4]
val = "01-{}-2011 00:00:01.978".format(month_abbr)
val = f"01-{month_abbr}-2011 00:00:01.978"

format = "%d-%b-%Y %H:%M:%S.%f"
result = to_datetime(val, format=format, cache=cache)
Expand Down Expand Up @@ -551,7 +551,7 @@ def test_to_datetime_dt64s(self, cache):
)
@pytest.mark.parametrize("cache", [True, False])
def test_to_datetime_dt64s_out_of_bounds(self, cache, dt):
msg = "Out of bounds nanosecond timestamp: {}".format(dt)
msg = f"Out of bounds nanosecond timestamp: {dt}"
with pytest.raises(OutOfBoundsDatetime, match=msg):
pd.to_datetime(dt, errors="raise")
with pytest.raises(OutOfBoundsDatetime, match=msg):
Expand Down
12 changes: 2 additions & 10 deletions pandas/tests/indexes/interval/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ def test_get_loc_interval(self, closed, side):
for bound in [[0, 1], [1, 2], [2, 3], [3, 4], [0, 2], [2.5, 3], [-1, 4]]:
# if get_loc is supplied an interval, it should only search
# for exact matches, not overlaps or covers, else KeyError.
msg = re.escape(
"Interval({bound[0]}, {bound[1]}, closed='{side}')".format(
bound=bound, side=side
)
)
msg = re.escape(f"Interval({bound[0]}, {bound[1]}, closed='{side}')")
if closed == side:
if bound == [0, 1]:
assert idx.get_loc(Interval(0, 1, closed=side)) == 0
Expand Down Expand Up @@ -86,11 +82,7 @@ def test_get_loc_length_one_interval(self, left, right, closed, other_closed):
else:
with pytest.raises(
KeyError,
match=re.escape(
"Interval({left}, {right}, closed='{other_closed}')".format(
left=left, right=right, other_closed=other_closed
)
),
match=re.escape(f"Interval({left}, {right}, closed='{other_closed}')"),
):
index.get_loc(interval)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/indexes/interval/test_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ def test_set_closed(self, name, closed, new_closed):
def test_set_closed_errors(self, bad_closed):
# GH 21670
index = interval_range(0, 5)
msg = "invalid option for 'closed': {closed}".format(closed=bad_closed)
msg = f"invalid option for 'closed': {bad_closed}"
with pytest.raises(ValueError, match=msg):
index.set_closed(bad_closed)

Expand Down