Skip to content

Commit d1173de

Browse files
yashuklajreback
authored andcommitted
CLN: F-string formatting in pandas/tests/indexes/*.py (#29547) (#29579)
1 parent db4095e commit d1173de

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

Diff for: pandas/tests/indexes/test_base.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ def test_drop_tuple(self, values, to_drop):
18321832
tm.assert_index_equal(result, expected)
18331833

18341834
removed = index.drop(to_drop[1])
1835-
msg = r"\"\[{}\] not found in axis\"".format(re.escape(to_drop[1].__repr__()))
1835+
msg = fr"\"\[{re.escape(to_drop[1].__repr__())}\] not found in axis\""
18361836
for drop_me in to_drop[1], [to_drop[1]]:
18371837
with pytest.raises(KeyError, match=msg):
18381838
removed.drop(drop_me)
@@ -2000,11 +2000,11 @@ def test_isin_level_kwarg_bad_label_raises(self, label, indices):
20002000
index = indices
20012001
if isinstance(index, MultiIndex):
20022002
index = index.rename(["foo", "bar"])
2003-
msg = "'Level {} not found'"
2003+
msg = f"'Level {label} not found'"
20042004
else:
20052005
index = index.rename("foo")
2006-
msg = r"Requested level \({}\) does not match index name \(foo\)"
2007-
with pytest.raises(KeyError, match=msg.format(label)):
2006+
msg = fr"Requested level \({label}\) does not match index name \(foo\)"
2007+
with pytest.raises(KeyError, match=msg):
20082008
index.isin([], level=label)
20092009

20102010
@pytest.mark.parametrize("empty", [[], Series(), np.array([])])
@@ -2755,7 +2755,7 @@ def test_generated_op_names(opname, indices):
27552755
# pd.Index.__rsub__ does not exist; though the method does exist
27562756
# for subclasses. see GH#19723
27572757
return
2758-
opname = "__{name}__".format(name=opname)
2758+
opname = f"__{opname}__"
27592759
method = getattr(indices, opname)
27602760
assert method.__name__ == opname
27612761

Diff for: pandas/tests/indexes/test_category.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ def test_disallow_set_ops(self, func, op_name):
188188
# GH 10039
189189
# set ops (+/-) raise TypeError
190190
idx = pd.Index(pd.Categorical(["a", "b"]))
191-
msg = "cannot perform {} with this index type: CategoricalIndex"
192-
with pytest.raises(TypeError, match=msg.format(op_name)):
191+
msg = f"cannot perform {op_name} with this index type: CategoricalIndex"
192+
with pytest.raises(TypeError, match=msg):
193193
func(idx)
194194

195195
def test_method_delegation(self):

Diff for: pandas/tests/indexes/test_common.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def test_dtype_str(self, indices):
167167
def test_hash_error(self, indices):
168168
index = indices
169169
with pytest.raises(
170-
TypeError, match=("unhashable type: {0.__name__!r}".format(type(index)))
170+
TypeError, match=(f"unhashable type: {type(index).__name__!r}")
171171
):
172172
hash(indices)
173173

@@ -201,8 +201,9 @@ def test_unique(self, indices):
201201
with pytest.raises(IndexError, match=msg):
202202
indices.unique(level=3)
203203

204-
msg = r"Requested level \(wrong\) does not match index name \({}\)".format(
205-
re.escape(indices.name.__repr__())
204+
msg = (
205+
fr"Requested level \(wrong\) does not match index name "
206+
fr"\({re.escape(indices.name.__repr__())}\)"
206207
)
207208
with pytest.raises(KeyError, match=msg):
208209
indices.unique(level="wrong")

Diff for: pandas/tests/indexes/test_numeric.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ def test_astype(self, mixed_index, float_index):
245245
# invalid
246246
for dtype in ["M8[ns]", "m8[ns]"]:
247247
msg = (
248-
"Cannot convert Float64Index to dtype {}; integer values"
249-
" are required for conversion"
250-
).format(pandas_dtype(dtype))
248+
f"Cannot convert Float64Index to dtype {pandas_dtype(dtype)}; "
249+
f"integer values are required for conversion"
250+
)
251251
with pytest.raises(TypeError, match=re.escape(msg)):
252252
i.astype(dtype)
253253

@@ -588,7 +588,7 @@ def test_take_fill_value(self):
588588
tm.assert_index_equal(result, expected)
589589

590590
name = self._holder.__name__
591-
msg = "Unable to fill values because {name} cannot contain NA".format(name=name)
591+
msg = f"Unable to fill values because {name} cannot contain NA"
592592

593593
# fill_value=True
594594
with pytest.raises(ValueError, match=msg):

0 commit comments

Comments
 (0)