Skip to content

Commit 72bc92e

Browse files
authored
CLN: 29547 replace old string formatting 3 (#31945)
1 parent 870ef1e commit 72bc92e

File tree

5 files changed

+50
-52
lines changed

5 files changed

+50
-52
lines changed

pandas/tests/indexes/interval/test_setops.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ def test_set_incompatible_types(self, closed, op_name, sort):
180180
# GH 19016: incompatible dtypes
181181
other = interval_range(Timestamp("20180101"), periods=9, closed=closed)
182182
msg = (
183-
"can only do {op} between two IntervalIndex objects that have "
183+
f"can only do {op_name} between two IntervalIndex objects that have "
184184
"compatible dtypes"
185-
).format(op=op_name)
185+
)
186186
with pytest.raises(TypeError, match=msg):
187187
set_op(other, sort=sort)

pandas/tests/indexes/multi/test_compat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_numeric_compat(idx):
2929

3030
@pytest.mark.parametrize("method", ["all", "any"])
3131
def test_logical_compat(idx, method):
32-
msg = "cannot perform {method}".format(method=method)
32+
msg = f"cannot perform {method}"
3333

3434
with pytest.raises(TypeError, match=msg):
3535
getattr(idx, method)()

pandas/tests/indexes/period/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def test_constructor_year_and_quarter(self):
364364
year = pd.Series([2001, 2002, 2003])
365365
quarter = year - 2000
366366
idx = PeriodIndex(year=year, quarter=quarter)
367-
strs = ["{t[0]:d}Q{t[1]:d}".format(t=t) for t in zip(quarter, year)]
367+
strs = [f"{t[0]:d}Q{t[1]:d}" for t in zip(quarter, year)]
368368
lops = list(map(Period, strs))
369369
p = PeriodIndex(lops)
370370
tm.assert_index_equal(p, idx)

pandas/tests/indexes/timedeltas/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_constructor(self):
155155
def test_constructor_iso(self):
156156
# GH #21877
157157
expected = timedelta_range("1s", periods=9, freq="s")
158-
durations = ["P0DT0H0M{}S".format(i) for i in range(1, 10)]
158+
durations = [f"P0DT0H0M{i}S" for i in range(1, 10)]
159159
result = to_timedelta(durations)
160160
tm.assert_index_equal(result, expected)
161161

pandas/tests/indexing/test_floats.py

+45-47
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def test_scalar_error(self, index_func):
5353
s.iloc[3.0]
5454

5555
msg = (
56-
"cannot do positional indexing on {klass} with these "
57-
r"indexers \[3\.0\] of type float".format(klass=type(i).__name__)
56+
fr"cannot do positional indexing on {type(i).__name__} with these "
57+
r"indexers \[3\.0\] of type float"
5858
)
5959
with pytest.raises(TypeError, match=msg):
6060
s.iloc[3.0] = 0
@@ -95,10 +95,10 @@ def test_scalar_non_numeric(self, index_func):
9595
error = TypeError
9696
msg = (
9797
r"cannot do (label|positional) indexing "
98-
r"on {klass} with these indexers \[3\.0\] of "
98+
fr"on {type(i).__name__} with these indexers \[3\.0\] of "
9999
r"type float|"
100100
"Cannot index by location index with a "
101-
"non-integer key".format(klass=type(i).__name__)
101+
"non-integer key"
102102
)
103103
with pytest.raises(error, match=msg):
104104
idxr(s)[3.0]
@@ -116,8 +116,8 @@ def test_scalar_non_numeric(self, index_func):
116116
error = TypeError
117117
msg = (
118118
r"cannot do (label|positional) indexing "
119-
r"on {klass} with these indexers \[3\.0\] of "
120-
r"type float".format(klass=type(i).__name__)
119+
fr"on {type(i).__name__} with these indexers \[3\.0\] of "
120+
"type float"
121121
)
122122
with pytest.raises(error, match=msg):
123123
s.loc[3.0]
@@ -128,8 +128,8 @@ def test_scalar_non_numeric(self, index_func):
128128
# setting with a float fails with iloc
129129
msg = (
130130
r"cannot do (label|positional) indexing "
131-
r"on {klass} with these indexers \[3\.0\] of "
132-
r"type float".format(klass=type(i).__name__)
131+
fr"on {type(i).__name__} with these indexers \[3\.0\] of "
132+
"type float"
133133
)
134134
with pytest.raises(TypeError, match=msg):
135135
s.iloc[3.0] = 0
@@ -165,8 +165,8 @@ def test_scalar_non_numeric(self, index_func):
165165
s[3]
166166
msg = (
167167
r"cannot do (label|positional) indexing "
168-
r"on {klass} with these indexers \[3\.0\] of "
169-
r"type float".format(klass=type(i).__name__)
168+
fr"on {type(i).__name__} with these indexers \[3\.0\] of "
169+
"type float"
170170
)
171171
with pytest.raises(TypeError, match=msg):
172172
s[3.0]
@@ -181,12 +181,10 @@ def test_scalar_with_mixed(self):
181181
for idxr in [lambda x: x, lambda x: x.iloc]:
182182

183183
msg = (
184-
r"cannot do label indexing "
185-
r"on {klass} with these indexers \[1\.0\] of "
184+
"cannot do label indexing "
185+
fr"on {Index.__name__} with these indexers \[1\.0\] of "
186186
r"type float|"
187-
"Cannot index by location index with a non-integer key".format(
188-
klass=Index.__name__
189-
)
187+
"Cannot index by location index with a non-integer key"
190188
)
191189
with pytest.raises(TypeError, match=msg):
192190
idxr(s2)[1.0]
@@ -203,9 +201,9 @@ def test_scalar_with_mixed(self):
203201
for idxr in [lambda x: x]:
204202

205203
msg = (
206-
r"cannot do label indexing "
207-
r"on {klass} with these indexers \[1\.0\] of "
208-
r"type float".format(klass=Index.__name__)
204+
"cannot do label indexing "
205+
fr"on {Index.__name__} with these indexers \[1\.0\] of "
206+
"type float"
209207
)
210208
with pytest.raises(TypeError, match=msg):
211209
idxr(s3)[1.0]
@@ -321,9 +319,9 @@ def test_scalar_float(self):
321319
s.iloc[3.0]
322320

323321
msg = (
324-
r"cannot do positional indexing "
325-
r"on {klass} with these indexers \[3\.0\] of "
326-
r"type float".format(klass=Float64Index.__name__)
322+
"cannot do positional indexing "
323+
fr"on {Float64Index.__name__} with these indexers \[3\.0\] of "
324+
"type float"
327325
)
328326
with pytest.raises(TypeError, match=msg):
329327
s2.iloc[3.0] = 0
@@ -355,8 +353,8 @@ def test_slice_non_numeric(self, index_func):
355353

356354
msg = (
357355
"cannot do positional indexing "
358-
r"on {klass} with these indexers \[(3|4)\.0\] of "
359-
"type float".format(klass=type(index).__name__)
356+
fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of "
357+
"type float"
360358
)
361359
with pytest.raises(TypeError, match=msg):
362360
s.iloc[l]
@@ -365,9 +363,9 @@ def test_slice_non_numeric(self, index_func):
365363

366364
msg = (
367365
"cannot do (slice|positional) indexing "
368-
r"on {klass} with these indexers "
366+
fr"on {type(index).__name__} with these indexers "
369367
r"\[(3|4)(\.0)?\] "
370-
r"of type (float|int)".format(klass=type(index).__name__)
368+
r"of type (float|int)"
371369
)
372370
with pytest.raises(TypeError, match=msg):
373371
idxr(s)[l]
@@ -377,18 +375,18 @@ def test_slice_non_numeric(self, index_func):
377375

378376
msg = (
379377
"cannot do positional indexing "
380-
r"on {klass} with these indexers \[(3|4)\.0\] of "
381-
"type float".format(klass=type(index).__name__)
378+
fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of "
379+
"type float"
382380
)
383381
with pytest.raises(TypeError, match=msg):
384382
s.iloc[l] = 0
385383

386384
for idxr in [lambda x: x.loc, lambda x: x.iloc, lambda x: x]:
387385
msg = (
388386
"cannot do (slice|positional) indexing "
389-
r"on {klass} with these indexers "
387+
fr"on {type(index).__name__} with these indexers "
390388
r"\[(3|4)(\.0)?\] "
391-
r"of type (float|int)".format(klass=type(index).__name__)
389+
r"of type (float|int)"
392390
)
393391
with pytest.raises(TypeError, match=msg):
394392
idxr(s)[l] = 0
@@ -427,8 +425,8 @@ def test_slice_integer(self):
427425
# positional indexing
428426
msg = (
429427
"cannot do slice indexing "
430-
r"on {klass} with these indexers \[(3|4)\.0\] of "
431-
"type float".format(klass=type(index).__name__)
428+
fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of "
429+
"type float"
432430
)
433431
with pytest.raises(TypeError, match=msg):
434432
s[l]
@@ -451,8 +449,8 @@ def test_slice_integer(self):
451449
# positional indexing
452450
msg = (
453451
"cannot do slice indexing "
454-
r"on {klass} with these indexers \[-6\.0\] of "
455-
"type float".format(klass=type(index).__name__)
452+
fr"on {type(index).__name__} with these indexers \[-6\.0\] of "
453+
"type float"
456454
)
457455
with pytest.raises(TypeError, match=msg):
458456
s[slice(-6.0, 6.0)]
@@ -477,8 +475,8 @@ def test_slice_integer(self):
477475
# positional indexing
478476
msg = (
479477
"cannot do slice indexing "
480-
r"on {klass} with these indexers \[(2|3)\.5\] of "
481-
"type float".format(klass=type(index).__name__)
478+
fr"on {type(index).__name__} with these indexers \[(2|3)\.5\] of "
479+
"type float"
482480
)
483481
with pytest.raises(TypeError, match=msg):
484482
s[l]
@@ -495,8 +493,8 @@ def test_slice_integer(self):
495493
# positional indexing
496494
msg = (
497495
"cannot do slice indexing "
498-
r"on {klass} with these indexers \[(3|4)\.0\] of "
499-
"type float".format(klass=type(index).__name__)
496+
fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of "
497+
"type float"
500498
)
501499
with pytest.raises(TypeError, match=msg):
502500
s[l] = 0
@@ -518,8 +516,8 @@ def test_integer_positional_indexing(self):
518516
klass = RangeIndex
519517
msg = (
520518
"cannot do (slice|positional) indexing "
521-
r"on {klass} with these indexers \[(2|4)\.0\] of "
522-
"type float".format(klass=klass.__name__)
519+
fr"on {klass.__name__} with these indexers \[(2|4)\.0\] of "
520+
"type float"
523521
)
524522
with pytest.raises(TypeError, match=msg):
525523
idxr(s)[l]
@@ -546,8 +544,8 @@ def f(idxr):
546544
# positional indexing
547545
msg = (
548546
"cannot do slice indexing "
549-
r"on {klass} with these indexers \[(0|1)\.0\] of "
550-
"type float".format(klass=type(index).__name__)
547+
fr"on {type(index).__name__} with these indexers \[(0|1)\.0\] of "
548+
"type float"
551549
)
552550
with pytest.raises(TypeError, match=msg):
553551
s[l]
@@ -561,8 +559,8 @@ def f(idxr):
561559
# positional indexing
562560
msg = (
563561
"cannot do slice indexing "
564-
r"on {klass} with these indexers \[-10\.0\] of "
565-
"type float".format(klass=type(index).__name__)
562+
fr"on {type(index).__name__} with these indexers \[-10\.0\] of "
563+
"type float"
566564
)
567565
with pytest.raises(TypeError, match=msg):
568566
s[slice(-10.0, 10.0)]
@@ -580,8 +578,8 @@ def f(idxr):
580578
# positional indexing
581579
msg = (
582580
"cannot do slice indexing "
583-
r"on {klass} with these indexers \[0\.5\] of "
584-
"type float".format(klass=type(index).__name__)
581+
fr"on {type(index).__name__} with these indexers \[0\.5\] of "
582+
"type float"
585583
)
586584
with pytest.raises(TypeError, match=msg):
587585
s[l]
@@ -597,8 +595,8 @@ def f(idxr):
597595
# positional indexing
598596
msg = (
599597
"cannot do slice indexing "
600-
r"on {klass} with these indexers \[(3|4)\.0\] of "
601-
"type float".format(klass=type(index).__name__)
598+
fr"on {type(index).__name__} with these indexers \[(3|4)\.0\] of "
599+
"type float"
602600
)
603601
with pytest.raises(TypeError, match=msg):
604602
s[l] = 0

0 commit comments

Comments
 (0)