Skip to content

CLN: F-string formatting in pandas/tests/indexes/*.py (#29547) #29579

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 2 commits into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1837,7 +1837,7 @@ def test_drop_tuple(self, values, to_drop):
tm.assert_index_equal(result, expected)

removed = index.drop(to_drop[1])
msg = r"\"\[{}\] not found in axis\"".format(re.escape(to_drop[1].__repr__()))
msg = fr"\"\[{re.escape(to_drop[1].__repr__())}\] not found in axis\""
for drop_me in to_drop[1], [to_drop[1]]:
with pytest.raises(KeyError, match=msg):
removed.drop(drop_me)
Expand Down Expand Up @@ -2005,11 +2005,11 @@ def test_isin_level_kwarg_bad_label_raises(self, label, indices):
index = indices
if isinstance(index, MultiIndex):
index = index.rename(["foo", "bar"])
msg = "'Level {} not found'"
msg = f"'Level {label} not found'"
else:
index = index.rename("foo")
msg = r"Requested level \({}\) does not match index name \(foo\)"
with pytest.raises(KeyError, match=msg.format(label)):
msg = fr"Requested level \({label}\) does not match index name \(foo\)"
with pytest.raises(KeyError, match=msg):
index.isin([], level=label)

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

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ def test_disallow_set_ops(self, func, op_name):
# GH 10039
# set ops (+/-) raise TypeError
idx = pd.Index(pd.Categorical(["a", "b"]))
msg = "cannot perform {} with this index type: CategoricalIndex"
with pytest.raises(TypeError, match=msg.format(op_name)):
msg = f"cannot perform {op_name} with this index type: CategoricalIndex"
with pytest.raises(TypeError, match=msg):
func(idx)

def test_method_delegation(self):
Expand Down
7 changes: 4 additions & 3 deletions pandas/tests/indexes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_dtype_str(self, indices):
def test_hash_error(self, indices):
index = indices
with pytest.raises(
TypeError, match=("unhashable type: {0.__name__!r}".format(type(index)))
TypeError, match=(f"unhashable type: {type(index).__name__!r}")
):
hash(indices)

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

msg = r"Requested level \(wrong\) does not match index name \({}\)".format(
re.escape(indices.name.__repr__())
msg = (
fr"Requested level \(wrong\) does not match index name "
fr"\({re.escape(indices.name.__repr__())}\)"
)
with pytest.raises(KeyError, match=msg):
indices.unique(level="wrong")
Expand Down
8 changes: 4 additions & 4 deletions pandas/tests/indexes/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ def test_astype(self, mixed_index, float_index):
# invalid
for dtype in ["M8[ns]", "m8[ns]"]:
msg = (
"Cannot convert Float64Index to dtype {}; integer values"
" are required for conversion"
).format(pandas_dtype(dtype))
f"Cannot convert Float64Index to dtype {pandas_dtype(dtype)}; "
f"integer values are required for conversion"
)
with pytest.raises(TypeError, match=re.escape(msg)):
i.astype(dtype)

Expand Down Expand Up @@ -588,7 +588,7 @@ def test_take_fill_value(self):
tm.assert_index_equal(result, expected)

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

# fill_value=True
with pytest.raises(ValueError, match=msg):
Expand Down