diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e19021762792f..9d9eee5070377 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index 16ee7c27780ca..658d27160e3e1 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -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) diff --git a/pandas/tests/frame/methods/test_to_period.py b/pandas/tests/frame/methods/test_to_period.py index eac78e611b008..051461b6c554d 100644 --- a/pandas/tests/frame/methods/test_to_period.py +++ b/pandas/tests/frame/methods/test_to_period.py @@ -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 " + msg = "No axis named 2 for object type DataFrame" with pytest.raises(ValueError, match=msg): df.to_period(axis=2) diff --git a/pandas/tests/generic/test_series.py b/pandas/tests/generic/test_series.py index bfdfd6d319b3f..229c6782e995e 100644 --- a/pandas/tests/generic/test_series.py +++ b/pandas/tests/generic/test_series.py @@ -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):