Skip to content

Commit 50dad9c

Browse files
authored
CLN: 29547 replace old string formatting 2 (#31933)
1 parent 8a7fbbe commit 50dad9c

File tree

7 files changed

+15
-21
lines changed

7 files changed

+15
-21
lines changed

pandas/tests/frame/test_operators.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,8 @@ def test_inplace_ops_identity2(self, op):
840840
df["a"] = [True, False, True]
841841

842842
df_copy = df.copy()
843-
iop = "__i{}__".format(op)
844-
op = "__{}__".format(op)
843+
iop = f"__i{op}__"
844+
op = f"__{op}__"
845845

846846
# no id change and value is correct
847847
getattr(df, iop)(operand)

pandas/tests/frame/test_reshape.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,9 @@ def test_unstack_unused_level(self, cols):
765765
tm.assert_frame_equal(result, expected)
766766

767767
def test_unstack_nan_index(self): # GH7466
768-
cast = lambda val: "{0:1}".format("" if val != val else val)
768+
def cast(val):
769+
val_str = "" if val != val else val
770+
return f"{val_str:1}"
769771

770772
def verify(df):
771773
mk_list = lambda a: list(a) if isinstance(a, tuple) else [a]

pandas/tests/frame/test_timeseries.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_frame_append_datetime64_col_other_units(self):
5454
ns_dtype = np.dtype("M8[ns]")
5555

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

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

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

7676
tmp = df.copy()

pandas/tests/indexes/datetimes/test_scalar_compat.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,21 @@ def test_round_int64(self, start, index_freq, periods, round_freq):
248248
result = dt.floor(round_freq)
249249
diff = dt.asi8 - result.asi8
250250
mod = result.asi8 % unit
251-
assert (mod == 0).all(), "floor not a {} multiple".format(round_freq)
251+
assert (mod == 0).all(), f"floor not a {round_freq} multiple"
252252
assert (0 <= diff).all() and (diff < unit).all(), "floor error"
253253

254254
# test ceil
255255
result = dt.ceil(round_freq)
256256
diff = result.asi8 - dt.asi8
257257
mod = result.asi8 % unit
258-
assert (mod == 0).all(), "ceil not a {} multiple".format(round_freq)
258+
assert (mod == 0).all(), f"ceil not a {round_freq} multiple"
259259
assert (0 <= diff).all() and (diff < unit).all(), "ceil error"
260260

261261
# test round
262262
result = dt.round(round_freq)
263263
diff = abs(result.asi8 - dt.asi8)
264264
mod = result.asi8 % unit
265-
assert (mod == 0).all(), "round not a {} multiple".format(round_freq)
265+
assert (mod == 0).all(), f"round not a {round_freq} multiple"
266266
assert (diff <= unit // 2).all(), "round error"
267267
if unit % 2 == 0:
268268
assert (

pandas/tests/indexes/datetimes/test_tools.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def test_to_datetime_format_microsecond(self, cache):
199199
# these are locale dependent
200200
lang, _ = locale.getlocale()
201201
month_abbr = calendar.month_abbr[4]
202-
val = "01-{}-2011 00:00:01.978".format(month_abbr)
202+
val = f"01-{month_abbr}-2011 00:00:01.978"
203203

204204
format = "%d-%b-%Y %H:%M:%S.%f"
205205
result = to_datetime(val, format=format, cache=cache)
@@ -551,7 +551,7 @@ def test_to_datetime_dt64s(self, cache):
551551
)
552552
@pytest.mark.parametrize("cache", [True, False])
553553
def test_to_datetime_dt64s_out_of_bounds(self, cache, dt):
554-
msg = "Out of bounds nanosecond timestamp: {}".format(dt)
554+
msg = f"Out of bounds nanosecond timestamp: {dt}"
555555
with pytest.raises(OutOfBoundsDatetime, match=msg):
556556
pd.to_datetime(dt, errors="raise")
557557
with pytest.raises(OutOfBoundsDatetime, match=msg):

pandas/tests/indexes/interval/test_indexing.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ def test_get_loc_interval(self, closed, side):
2424
for bound in [[0, 1], [1, 2], [2, 3], [3, 4], [0, 2], [2.5, 3], [-1, 4]]:
2525
# if get_loc is supplied an interval, it should only search
2626
# for exact matches, not overlaps or covers, else KeyError.
27-
msg = re.escape(
28-
"Interval({bound[0]}, {bound[1]}, closed='{side}')".format(
29-
bound=bound, side=side
30-
)
31-
)
27+
msg = re.escape(f"Interval({bound[0]}, {bound[1]}, closed='{side}')")
3228
if closed == side:
3329
if bound == [0, 1]:
3430
assert idx.get_loc(Interval(0, 1, closed=side)) == 0
@@ -86,11 +82,7 @@ def test_get_loc_length_one_interval(self, left, right, closed, other_closed):
8682
else:
8783
with pytest.raises(
8884
KeyError,
89-
match=re.escape(
90-
"Interval({left}, {right}, closed='{other_closed}')".format(
91-
left=left, right=right, other_closed=other_closed
92-
)
93-
),
85+
match=re.escape(f"Interval({left}, {right}, closed='{other_closed}')"),
9486
):
9587
index.get_loc(interval)
9688

pandas/tests/indexes/interval/test_interval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ def test_set_closed(self, name, closed, new_closed):
845845
def test_set_closed_errors(self, bad_closed):
846846
# GH 21670
847847
index = interval_range(0, 5)
848-
msg = "invalid option for 'closed': {closed}".format(closed=bad_closed)
848+
msg = f"invalid option for 'closed': {bad_closed}"
849849
with pytest.raises(ValueError, match=msg):
850850
index.set_closed(bad_closed)
851851

0 commit comments

Comments
 (0)