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

Diff for: doc/source/whatsnew/v0.25.0.rst

+1-1
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

Diff for: pandas/core/generic.py

+2-2
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)

Diff for: pandas/tests/frame/test_analytics.py

+4-2
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

Diff for: pandas/tests/frame/test_api.py

+2-1
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

Diff for: pandas/tests/frame/test_axis_select_reindex.py

+2-1
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

Diff for: pandas/tests/frame/test_missing.py

+2-1
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

Diff for: pandas/tests/frame/test_quantile.py

+4-2
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

Diff for: pandas/tests/frame/test_sorting.py

+2-1
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

Diff for: pandas/tests/frame/test_timeseries.py

+2-1
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

Diff for: pandas/tests/series/test_analytics.py

+3-1
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):

Diff for: pandas/tests/series/test_missing.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import pytz
1111

1212
from pandas._libs.tslib import iNaT
13-
from pandas.compat import range
13+
from pandas.compat import PY2, range
1414
from pandas.errors import PerformanceWarning
1515
import pandas.util._test_decorators as td
1616

@@ -654,14 +654,16 @@ def test_timedelta64_nan(self):
654654
# expected = (datetime_series >= -0.5) & (datetime_series <= 0.5)
655655
# assert_series_equal(selector, expected)
656656

657+
@pytest.mark.skipif(PY2, reason="pytest.raises match regex fails")
657658
def test_dropna_empty(self):
658659
s = Series([])
659660
assert len(s.dropna()) == 0
660661
s.dropna(inplace=True)
661662
assert len(s) == 0
662663

663664
# invalid axis
664-
msg = r"No axis named 1 for object type <(class|type) 'type'>"
665+
msg = ("No axis named 1 for object type"
666+
" <class 'pandas.core.series.Series'>")
665667
with pytest.raises(ValueError, match=msg):
666668
s.dropna(axis=1)
667669

Diff for: pandas/tests/series/test_rank.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pandas._libs.algos import Infinity, NegInfinity
1010
from pandas._libs.tslib import iNaT
1111
import pandas.compat as compat
12-
from pandas.compat import product
12+
from pandas.compat import PY2, product
1313
import pandas.util._test_decorators as td
1414

1515
from pandas import NaT, Series, Timestamp, date_range
@@ -203,10 +203,12 @@ def test_rank_categorical(self):
203203
assert_series_equal(na_ser.rank(na_option='bottom', pct=True), exp_bot)
204204
assert_series_equal(na_ser.rank(na_option='keep', pct=True), exp_keep)
205205

206+
@pytest.mark.skipif(PY2, reason="pytest.raises match regex fails")
206207
def test_rank_signature(self):
207208
s = Series([0, 1])
208209
s.rank(method='average')
209-
msg = r"No axis named average for object type <(class|type) 'type'>"
210+
msg = ("No axis named average for object type"
211+
" <class 'pandas.core.series.Series'>")
210212
with pytest.raises(ValueError, match=msg):
211213
s.rank('average')
212214

Diff for: pandas/tests/series/test_sorting.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import numpy as np
66
import pytest
77

8+
from pandas.compat import PY2
9+
810
from pandas import Categorical, DataFrame, IntervalIndex, MultiIndex, Series
911
import pandas.util.testing as tm
1012
from pandas.util.testing import assert_almost_equal, assert_series_equal
@@ -88,6 +90,7 @@ def test_sort_values(self):
8890
with pytest.raises(ValueError, match=msg):
8991
s.sort_values(inplace=True)
9092

93+
@pytest.mark.skipif(PY2, reason="pytest.raises match regex fails")
9194
def test_sort_index(self):
9295
rindex = list(self.ts.index)
9396
random.shuffle(rindex)
@@ -109,7 +112,8 @@ def test_sort_index(self):
109112
sorted_series = random_order.sort_index(axis=0)
110113
assert_series_equal(sorted_series, self.ts)
111114

112-
msg = r"No axis named 1 for object type <(class|type) 'type'>"
115+
msg = ("No axis named 1 for object type"
116+
" <class 'pandas.core.series.Series'>")
113117
with pytest.raises(ValueError, match=msg):
114118
random_order.sort_values(axis=1)
115119

Diff for: pandas/tests/series/test_timeseries.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from pandas._libs.tslib import iNaT
1010
from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime
11-
from pandas.compat import StringIO, lrange, product
11+
from pandas.compat import PY2, StringIO, lrange, product
1212
from pandas.errors import NullFrequencyError
1313
import pandas.util._test_decorators as td
1414

@@ -867,6 +867,7 @@ def test_between_time_formats(self):
867867
for time_string in strings:
868868
assert len(ts.between_time(*time_string)) == expected_length
869869

870+
@pytest.mark.skipif(PY2, reason="pytest.raises match regex fails")
870871
def test_between_time_axis(self):
871872
# issue 8839
872873
rng = date_range('1/1/2000', periods=100, freq='10min')
@@ -876,7 +877,8 @@ def test_between_time_axis(self):
876877

877878
assert len(ts.between_time(stime, etime)) == expected_length
878879
assert len(ts.between_time(stime, etime, axis=0)) == expected_length
879-
msg = r"No axis named 1 for object type <(class|type) 'type'>"
880+
msg = ("No axis named 1 for object type"
881+
" <class 'pandas.core.series.Series'>")
880882
with pytest.raises(ValueError, match=msg):
881883
ts.between_time(stime, etime, axis=1)
882884

0 commit comments

Comments
 (0)