Skip to content

TST: Avoid bare pytest.raises in test_series.py #32879

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
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def _get_axis_name(cls, axis):
return cls._AXIS_NAMES[axis]
except KeyError:
pass
raise ValueError(f"No axis named {axis} for object type {cls}")
raise ValueError(f"No axis named {axis} for object type {cls.__name__}")

def _get_axis(self, axis):
name = self._get_axis_name(axis)
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ def test_basic(self, dtype):

def test_empty(self):
dt = PeriodDtype()
# https://github.com/pandas-dev/pandas/issues/27388
msg = "object has no attribute 'freqstr'"
with pytest.raises(AttributeError, match=msg):
str(dt)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/frame/methods/test_to_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ def test_frame_to_period(self):
pts = df.to_period("M", axis=1)
tm.assert_index_equal(pts.columns, exp.columns.asfreq("M"))

msg = "No axis named 2 for object type <class 'pandas.core.frame.DataFrame'>"
msg = "No axis named 2 for object type DataFrame"
with pytest.raises(ValueError, match=msg):
df.to_period(axis=2)
3 changes: 2 additions & 1 deletion pandas/tests/generic/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def test_set_axis_name_mi(self, func):

def test_set_axis_name_raises(self):
s = pd.Series([1])
with pytest.raises(ValueError):
msg = "No axis named 1 for object type Series"
with pytest.raises(ValueError, match=msg):
s._set_axis_name(name="a", axis=1)

def test_get_numeric_data_preserve_dtype(self):
Expand Down