Skip to content

Commit 2b7fb24

Browse files
committed
CLN: Test cleanups and follow-ups
1 parent d18e14c commit 2b7fb24

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

pandas/tests/frame/test_alter_axes.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -1052,31 +1052,31 @@ def test_rename_positional_named(self):
10521052
tm.assert_frame_equal(result, expected)
10531053

10541054
def test_rename_axis_style_raises(self):
1055-
# https://github.com/pandas-dev/pandas/issues/12392
1056-
df = DataFrame({"A": [1, 2], "B": [1, 2]}, index=['0', '1'])
1055+
# see gh-12392
1056+
df = DataFrame({"A": [1, 2], "B": [1, 2]}, index=["0", "1"])
10571057

10581058
# Named target and axis
1059-
with pytest.raises(TypeError, match=None):
1059+
over_spec_msg = ("Cannot specify both 'axis' and "
1060+
"any of 'index' or 'columns'")
1061+
with pytest.raises(TypeError, match=over_spec_msg):
10601062
df.rename(index=str.lower, axis=1)
10611063

1062-
with pytest.raises(TypeError, match=None):
1063-
df.rename(index=str.lower, axis='columns')
1064-
1065-
with pytest.raises(TypeError, match=None):
1066-
df.rename(index=str.lower, axis='columns')
1064+
with pytest.raises(TypeError, match=over_spec_msg):
1065+
df.rename(index=str.lower, axis="columns")
10671066

1068-
with pytest.raises(TypeError, match=None):
1069-
df.rename(columns=str.lower, axis='columns')
1067+
with pytest.raises(TypeError, match=over_spec_msg):
1068+
df.rename(columns=str.lower, axis="columns")
10701069

1071-
with pytest.raises(TypeError, match=None):
1070+
with pytest.raises(TypeError, match=over_spec_msg):
10721071
df.rename(index=str.lower, axis=0)
10731072

10741073
# Multiple targets and axis
1075-
with pytest.raises(TypeError, match=None):
1076-
df.rename(str.lower, str.lower, axis='columns')
1074+
with pytest.raises(TypeError, match=over_spec_msg):
1075+
df.rename(str.lower, str.lower, axis="columns")
10771076

10781077
# Too many targets
1079-
with pytest.raises(TypeError, match=None):
1078+
over_spec_msg = "Cannot specify all of 'mapper', 'index', 'columns'."
1079+
with pytest.raises(TypeError, match=over_spec_msg):
10801080
df.rename(str.lower, str.lower, str.lower)
10811081

10821082
# Duplicates

pandas/tests/test_strings.py

+14-18
Original file line numberDiff line numberDiff line change
@@ -2114,29 +2114,25 @@ def test_center_ljust_rjust_fillchar(self):
21142114
# If fillchar is not a charatter, normal str raises TypeError
21152115
# 'aaa'.ljust(5, 'XY')
21162116
# TypeError: must be char, not str
2117-
msg = "fillchar must be a character, not str"
2118-
with pytest.raises(TypeError, match=msg):
2119-
result = values.str.center(5, fillchar='XY')
2117+
template = "fillchar must be a character, not {dtype}"
21202118

2121-
msg = "fillchar must be a character, not str"
2122-
with pytest.raises(TypeError, match=msg):
2123-
result = values.str.ljust(5, fillchar='XY')
2119+
with pytest.raises(TypeError, match=template.format(dtype="str")):
2120+
values.str.center(5, fillchar='XY')
21242121

2125-
msg = "fillchar must be a character, not str"
2126-
with pytest.raises(TypeError, match=msg):
2127-
result = values.str.rjust(5, fillchar='XY')
2122+
with pytest.raises(TypeError, match=template.format(dtype="str")):
2123+
values.str.ljust(5, fillchar='XY')
21282124

2129-
msg = "fillchar must be a character, not int"
2130-
with pytest.raises(TypeError, match=msg):
2131-
result = values.str.center(5, fillchar=1)
2125+
with pytest.raises(TypeError, match=template.format(dtype="str")):
2126+
values.str.rjust(5, fillchar='XY')
21322127

2133-
msg = "fillchar must be a character, not int"
2134-
with pytest.raises(TypeError, match=msg):
2135-
result = values.str.ljust(5, fillchar=1)
2128+
with pytest.raises(TypeError, match=template.format(dtype="int")):
2129+
values.str.center(5, fillchar=1)
21362130

2137-
msg = "fillchar must be a character, not int"
2138-
with pytest.raises(TypeError, match=msg):
2139-
result = values.str.rjust(5, fillchar=1)
2131+
with pytest.raises(TypeError, match=template.format(dtype="int")):
2132+
values.str.ljust(5, fillchar=1)
2133+
2134+
with pytest.raises(TypeError, match=template.format(dtype="int")):
2135+
values.str.rjust(5, fillchar=1)
21402136

21412137
def test_zfill(self):
21422138
values = Series(['1', '22', 'aaa', '333', '45678'])

0 commit comments

Comments
 (0)