Skip to content

Commit 04a884d

Browse files
committed
CLN: F-string formatting in pandas/tests/indexes/*.py (pandas-dev#29527)
1 parent 5c36aa1 commit 04a884d

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

pandas/tests/indexes/test_base.py

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

18391839
removed = index.drop(to_drop[1])
1840-
msg = r"\"\[{}\] not found in axis\"".format(re.escape(to_drop[1].__repr__()))
1840+
msg = fr"\"\[{re.escape(to_drop[1].__repr__())}\] not found in axis\""
18411841
for drop_me in to_drop[1], [to_drop[1]]:
18421842
with pytest.raises(KeyError, match=msg):
18431843
removed.drop(drop_me)
@@ -2005,11 +2005,11 @@ def test_isin_level_kwarg_bad_label_raises(self, label, indices):
20052005
index = indices
20062006
if isinstance(index, MultiIndex):
20072007
index = index.rename(["foo", "bar"])
2008-
msg = "'Level {} not found'"
2008+
msg = f"'Level {label} not found'"
20092009
else:
20102010
index = index.rename("foo")
2011-
msg = r"Requested level \({}\) does not match index name \(foo\)"
2012-
with pytest.raises(KeyError, match=msg.format(label)):
2011+
msg = fr"Requested level \({label}\) does not match index name \(foo\)"
2012+
with pytest.raises(KeyError, match=msg):
20132013
index.isin([], level=label)
20142014

20152015
@pytest.mark.parametrize("empty", [[], Series(), np.array([])])
@@ -2768,7 +2768,7 @@ def test_generated_op_names(opname, indices):
27682768
# pd.Index.__rsub__ does not exist; though the method does exist
27692769
# for subclasses. see GH#19723
27702770
return
2771-
opname = "__{name}__".format(name=opname)
2771+
opname = f"__{opname}__"
27722772
method = getattr(indices, opname)
27732773
assert method.__name__ == opname
27742774

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):

pandas/tests/indexes/test_common.py

+3-4
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=(fr"unhashable type: {type(index).__name__!r}")
171171
):
172172
hash(indices)
173173

@@ -201,9 +201,8 @@ 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__())
206-
)
204+
msg = fr"Requested level \(wrong\) does not match index name " \
205+
fr"\({re.escape(indices.name.__repr__())}\)"
207206
with pytest.raises(KeyError, match=msg):
208207
indices.unique(level="wrong")
209208

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)