Skip to content

Commit 1c72dda

Browse files
simonjayhawkinsjreback
authored andcommitted
BUG: in error message raised when invalid axis parameter (#25553)
1 parent 07625af commit 1c72dda

14 files changed

+41
-20
lines changed

doc/source/whatsnew/v0.25.0.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Missing
196196
^^^^^^^
197197

198198
- Fixed misleading exception message in :meth:`Series.missing` if argument ``order`` is required, but omitted (:issue:`10633`, :issue:`24014`).
199-
-
199+
- Fixed class type displayed in exception message in :meth:`DataFrame.dropna` if invalid ``axis`` parameter passed (:issue:`25555`)
200200
-
201201

202202
MultiIndex

pandas/core/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def _get_axis_number(cls, axis):
358358
except KeyError:
359359
pass
360360
raise ValueError('No axis named {0} for object type {1}'
361-
.format(axis, type(cls)))
361+
.format(axis, cls))
362362

363363
@classmethod
364364
def _get_axis_name(cls, axis):
@@ -372,7 +372,7 @@ def _get_axis_name(cls, axis):
372372
except KeyError:
373373
pass
374374
raise ValueError('No axis named {0} for object type {1}'
375-
.format(axis, type(cls)))
375+
.format(axis, cls))
376376

377377
def _get_axis(self, axis):
378378
name = self._get_axis_name(axis)

pandas/tests/frame/test_analytics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,8 @@ def test_idxmin(self, float_frame, int_frame):
13851385
skipna=skipna)
13861386
tm.assert_series_equal(result, expected)
13871387

1388-
msg = "No axis named 2 for object type <class 'type'>"
1388+
msg = ("No axis named 2 for object type"
1389+
" <class 'pandas.core.frame.DataFrame'>")
13891390
with pytest.raises(ValueError, match=msg):
13901391
frame.idxmin(axis=2)
13911392

@@ -1402,7 +1403,8 @@ def test_idxmax(self, float_frame, int_frame):
14021403
skipna=skipna)
14031404
tm.assert_series_equal(result, expected)
14041405

1405-
msg = "No axis named 2 for object type <class 'type'>"
1406+
msg = ("No axis named 2 for object type"
1407+
" <class 'pandas.core.frame.DataFrame'>")
14061408
with pytest.raises(ValueError, match=msg):
14071409
frame.idxmax(axis=2)
14081410

pandas/tests/frame/test_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ def test_swapaxes(self):
366366
self._assert_frame_equal(df.T, df.swapaxes(0, 1))
367367
self._assert_frame_equal(df.T, df.swapaxes(1, 0))
368368
self._assert_frame_equal(df, df.swapaxes(0, 0))
369-
msg = "No axis named 2 for object type <class 'type'>"
369+
msg = ("No axis named 2 for object type"
370+
r" <class 'pandas.core(.sparse)?.frame.(Sparse)?DataFrame'>")
370371
with pytest.raises(ValueError, match=msg):
371372
df.swapaxes(2, 5)
372373

pandas/tests/frame/test_axis_select_reindex.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,8 @@ def test_reindex_axis(self):
10671067
reindexed2 = self.intframe.reindex(index=rows)
10681068
assert_frame_equal(reindexed1, reindexed2)
10691069

1070-
msg = "No axis named 2 for object type <class 'type'>"
1070+
msg = ("No axis named 2 for object type"
1071+
" <class 'pandas.core.frame.DataFrame'>")
10711072
with pytest.raises(ValueError, match=msg):
10721073
self.intframe.reindex_axis(rows, axis=2)
10731074

pandas/tests/frame/test_missing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ def test_dropna(self):
140140
assert_frame_equal(dropped, expected)
141141

142142
# bad input
143-
msg = "No axis named 3 for object type <class 'type'>"
143+
msg = ("No axis named 3 for object type"
144+
" <class 'pandas.core.frame.DataFrame'>")
144145
with pytest.raises(ValueError, match=msg):
145146
df.dropna(axis=3)
146147

pandas/tests/frame/test_quantile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ def test_quantile_axis_parameter(self):
9595
result = df.quantile(.5, axis="columns")
9696
assert_series_equal(result, expected)
9797

98-
msg = "No axis named -1 for object type <class 'type'>"
98+
msg = ("No axis named -1 for object type"
99+
" <class 'pandas.core.frame.DataFrame'>")
99100
with pytest.raises(ValueError, match=msg):
100101
df.quantile(0.1, axis=-1)
101-
msg = "No axis named column for object type <class 'type'>"
102+
msg = ("No axis named column for object type"
103+
" <class 'pandas.core.frame.DataFrame'>")
102104
with pytest.raises(ValueError, match=msg):
103105
df.quantile(0.1, axis="column")
104106

pandas/tests/frame/test_sorting.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def test_sort_values(self):
5555
sorted_df = frame.sort_values(by=['B', 'A'], ascending=[True, False])
5656
assert_frame_equal(sorted_df, expected)
5757

58-
msg = "No axis named 2 for object type <class 'type'>"
58+
msg = ("No axis named 2 for object type"
59+
" <class 'pandas.core.frame.DataFrame'>")
5960
with pytest.raises(ValueError, match=msg):
6061
frame.sort_values(by=['A', 'B'], axis=2, inplace=True)
6162

pandas/tests/frame/test_timeseries.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,8 @@ def test_frame_to_period(self):
862862
pts = df.to_period('M', axis=1)
863863
tm.assert_index_equal(pts.columns, exp.columns.asfreq('M'))
864864

865-
msg = "No axis named 2 for object type <class 'type'>"
865+
msg = ("No axis named 2 for object type"
866+
" <class 'pandas.core.frame.DataFrame'>")
866867
with pytest.raises(ValueError, match=msg):
867868
df.to_period(axis=2)
868869

pandas/tests/series/test_analytics.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ def test_isin_empty(self, empty):
771771
result = s.isin(empty)
772772
tm.assert_series_equal(expected, result)
773773

774+
@pytest.mark.skipif(PY2, reason="pytest.raises match regex fails")
774775
def test_ptp(self):
775776
# GH21614
776777
N = 1000
@@ -796,7 +797,8 @@ def test_ptp(self):
796797
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
797798
tm.assert_series_equal(s.ptp(level=0, skipna=False), expected)
798799

799-
msg = r"No axis named 1 for object type <(class|type) 'type'>"
800+
msg = ("No axis named 1 for object type"
801+
" <class 'pandas.core.series.Series'>")
800802
with pytest.raises(ValueError, match=msg):
801803
with tm.assert_produces_warning(FutureWarning,
802804
check_stacklevel=False):

0 commit comments

Comments
 (0)