From e51d8bc36d6e4c5430068dfdf77e1837229d4969 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 5 Mar 2019 18:27:57 +0000 Subject: [PATCH 1/4] BUG: in error message raised when invalid axis parameter --- pandas/core/generic.py | 8 ++++---- pandas/tests/frame/test_analytics.py | 6 ++---- pandas/tests/frame/test_api.py | 5 ++--- pandas/tests/frame/test_axis_select_reindex.py | 5 ++--- pandas/tests/frame/test_missing.py | 5 ++--- pandas/tests/frame/test_quantile.py | 7 ++----- pandas/tests/frame/test_sorting.py | 5 ++--- pandas/tests/frame/test_timeseries.py | 5 ++--- pandas/tests/series/test_analytics.py | 2 +- pandas/tests/series/test_missing.py | 2 +- pandas/tests/series/test_rank.py | 2 +- pandas/tests/series/test_sorting.py | 2 +- pandas/tests/series/test_timeseries.py | 2 +- 13 files changed, 23 insertions(+), 33 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index ee8f9cba951b3..836fc324ac664 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -357,8 +357,8 @@ def _get_axis_number(cls, axis): return cls._AXIS_NUMBERS[axis] except KeyError: pass - raise ValueError('No axis named {0} for object type {1}' - .format(axis, type(cls))) + raise ValueError("No axis named {0} for object type '{1}'" + .format(axis, cls.__name__)) @classmethod def _get_axis_name(cls, axis): @@ -371,8 +371,8 @@ def _get_axis_name(cls, axis): return cls._AXIS_NAMES[axis] except KeyError: pass - raise ValueError('No axis named {0} for object type {1}' - .format(axis, type(cls))) + raise ValueError("No axis named {0} for object type '{1}'" + .format(axis, cls.__name__)) def _get_axis(self, axis): name = self._get_axis_name(axis) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 3363a45149fff..2581745d710f4 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1372,7 +1372,6 @@ def test_pct_change(self): # ---------------------------------------------------------------------- # Index of max / min - @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_idxmin(self, float_frame, int_frame): frame = float_frame frame.loc[5:10] = np.nan @@ -1385,11 +1384,10 @@ def test_idxmin(self, float_frame, int_frame): skipna=skipna) tm.assert_series_equal(result, expected) - msg = "No axis named 2 for object type " + msg = "No axis named 2 for object type 'DataFrame'" with pytest.raises(ValueError, match=msg): frame.idxmin(axis=2) - @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_idxmax(self, float_frame, int_frame): frame = float_frame frame.loc[5:10] = np.nan @@ -1402,7 +1400,7 @@ def test_idxmax(self, float_frame, int_frame): skipna=skipna) tm.assert_series_equal(result, expected) - msg = "No axis named 2 for object type " + msg = "No axis named 2 for object type 'DataFrame'" with pytest.raises(ValueError, match=msg): frame.idxmax(axis=2) diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 118341276d799..4db2078265895 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -9,7 +9,7 @@ import numpy as np import pytest -from pandas.compat import PY2, long, lrange, range +from pandas.compat import long, lrange, range import pandas as pd from pandas import ( @@ -360,13 +360,12 @@ def test_transpose(self, float_frame): for col, s in compat.iteritems(mixed_T): assert s.dtype == np.object_ - @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_swapaxes(self): df = self.klass(np.random.randn(10, 5)) self._assert_frame_equal(df.T, df.swapaxes(0, 1)) self._assert_frame_equal(df.T, df.swapaxes(1, 0)) self._assert_frame_equal(df, df.swapaxes(0, 0)) - msg = "No axis named 2 for object type " + msg = r"No axis named 2 for object type '(Sparse)?DataFrame'" with pytest.raises(ValueError, match=msg): df.swapaxes(2, 5) diff --git a/pandas/tests/frame/test_axis_select_reindex.py b/pandas/tests/frame/test_axis_select_reindex.py index fb00776b33cbb..f8f74b12b7990 100644 --- a/pandas/tests/frame/test_axis_select_reindex.py +++ b/pandas/tests/frame/test_axis_select_reindex.py @@ -7,7 +7,7 @@ import numpy as np import pytest -from pandas.compat import PY2, lrange, lzip, u +from pandas.compat import lrange, lzip, u from pandas.errors import PerformanceWarning import pandas as pd @@ -1051,7 +1051,6 @@ def test_reindex_corner(self): smaller = self.intframe.reindex(columns=['A', 'B', 'E']) assert smaller['E'].dtype == np.float64 - @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_reindex_axis(self): cols = ['A', 'B', 'E'] with tm.assert_produces_warning(FutureWarning) as m: @@ -1067,7 +1066,7 @@ def test_reindex_axis(self): reindexed2 = self.intframe.reindex(index=rows) assert_frame_equal(reindexed1, reindexed2) - msg = "No axis named 2 for object type " + msg = "No axis named 2 for object type 'DataFrame'" with pytest.raises(ValueError, match=msg): self.intframe.reindex_axis(rows, axis=2) diff --git a/pandas/tests/frame/test_missing.py b/pandas/tests/frame/test_missing.py index 2f3b0a9f76de9..c491ad7aa4973 100644 --- a/pandas/tests/frame/test_missing.py +++ b/pandas/tests/frame/test_missing.py @@ -9,7 +9,7 @@ import numpy as np import pytest -from pandas.compat import PY2, lrange +from pandas.compat import lrange import pandas.util._test_decorators as td import pandas as pd @@ -83,7 +83,6 @@ def test_dropIncompleteRows(self): tm.assert_index_equal(samesize_frame.index, self.frame.index) tm.assert_index_equal(inp_frame2.index, self.frame.index) - @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_dropna(self): df = DataFrame(np.random.randn(6, 4)) df[2][:2] = np.nan @@ -140,7 +139,7 @@ def test_dropna(self): assert_frame_equal(dropped, expected) # bad input - msg = "No axis named 3 for object type " + msg = "No axis named 3 for object type 'DataFrame'" with pytest.raises(ValueError, match=msg): df.dropna(axis=3) diff --git a/pandas/tests/frame/test_quantile.py b/pandas/tests/frame/test_quantile.py index 19b6636978643..03515705e48a8 100644 --- a/pandas/tests/frame/test_quantile.py +++ b/pandas/tests/frame/test_quantile.py @@ -5,8 +5,6 @@ import numpy as np import pytest -from pandas.compat import PY2 - import pandas as pd from pandas import DataFrame, Series, Timestamp from pandas.tests.frame.common import TestData @@ -73,7 +71,6 @@ def test_quantile_axis_mixed(self): with pytest.raises(TypeError): df.quantile(.5, axis=1, numeric_only=False) - @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_quantile_axis_parameter(self): # GH 9543/9544 @@ -95,10 +92,10 @@ def test_quantile_axis_parameter(self): result = df.quantile(.5, axis="columns") assert_series_equal(result, expected) - msg = "No axis named -1 for object type " + msg = "No axis named -1 for object type 'DataFrame'" with pytest.raises(ValueError, match=msg): df.quantile(0.1, axis=-1) - msg = "No axis named column for object type " + msg = "No axis named column for object type 'DataFrame'" with pytest.raises(ValueError, match=msg): df.quantile(0.1, axis="column") diff --git a/pandas/tests/frame/test_sorting.py b/pandas/tests/frame/test_sorting.py index 8b29394bcab84..aaab4a0769bb9 100644 --- a/pandas/tests/frame/test_sorting.py +++ b/pandas/tests/frame/test_sorting.py @@ -7,7 +7,7 @@ import numpy as np import pytest -from pandas.compat import PY2, lrange +from pandas.compat import lrange import pandas as pd from pandas import ( @@ -21,7 +21,6 @@ class TestDataFrameSorting(TestData): - @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_sort_values(self): frame = DataFrame([[1, 1, 2], [3, 1, 0], [4, 5, 6]], index=[1, 2, 3], columns=list('ABC')) @@ -55,7 +54,7 @@ def test_sort_values(self): sorted_df = frame.sort_values(by=['B', 'A'], ascending=[True, False]) assert_frame_equal(sorted_df, expected) - msg = "No axis named 2 for object type " + msg = "No axis named 2 for object type 'DataFrame'" with pytest.raises(ValueError, match=msg): frame.sort_values(by=['A', 'B'], axis=2, inplace=True) diff --git a/pandas/tests/frame/test_timeseries.py b/pandas/tests/frame/test_timeseries.py index 716a9e30e4cc3..12a75613bbeb9 100644 --- a/pandas/tests/frame/test_timeseries.py +++ b/pandas/tests/frame/test_timeseries.py @@ -8,7 +8,7 @@ import pytest import pytz -from pandas.compat import PY2, product +from pandas.compat import product import pandas as pd from pandas import ( @@ -836,7 +836,6 @@ def test_datetime_assignment_with_NaT_and_diff_time_units(self): 'new': [1e9, None]}, dtype='datetime64[ns]') tm.assert_frame_equal(result, expected) - @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_frame_to_period(self): K = 5 @@ -862,7 +861,7 @@ 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/series/test_analytics.py b/pandas/tests/series/test_analytics.py index 1f265d574da15..c87b10280ab06 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -796,7 +796,7 @@ def test_ptp(self): with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) - msg = r"No axis named 1 for object type <(class|type) 'type'>" + msg = "No axis named 1 for object type 'Series'" with pytest.raises(ValueError, match=msg): with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index f07dd1dfb5fda..d21a49e68a5a4 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -661,7 +661,7 @@ def test_dropna_empty(self): assert len(s) == 0 # invalid axis - msg = r"No axis named 1 for object type <(class|type) 'type'>" + msg = "No axis named 1 for object type 'Series'" with pytest.raises(ValueError, match=msg): s.dropna(axis=1) diff --git a/pandas/tests/series/test_rank.py b/pandas/tests/series/test_rank.py index dfcda889269ee..ab5ee11d31e49 100644 --- a/pandas/tests/series/test_rank.py +++ b/pandas/tests/series/test_rank.py @@ -206,7 +206,7 @@ def test_rank_categorical(self): def test_rank_signature(self): s = Series([0, 1]) s.rank(method='average') - msg = r"No axis named average for object type <(class|type) 'type'>" + msg = "No axis named average for object type 'Series'" with pytest.raises(ValueError, match=msg): s.rank('average') diff --git a/pandas/tests/series/test_sorting.py b/pandas/tests/series/test_sorting.py index 216f84c8f077a..a6dc4bc56e406 100644 --- a/pandas/tests/series/test_sorting.py +++ b/pandas/tests/series/test_sorting.py @@ -109,7 +109,7 @@ def test_sort_index(self): sorted_series = random_order.sort_index(axis=0) assert_series_equal(sorted_series, self.ts) - msg = r"No axis named 1 for object type <(class|type) 'type'>" + msg = "No axis named 1 for object type 'Series'" with pytest.raises(ValueError, match=msg): random_order.sort_values(axis=1) diff --git a/pandas/tests/series/test_timeseries.py b/pandas/tests/series/test_timeseries.py index d082b023e1f27..c75e8b74bbe6a 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -876,7 +876,7 @@ def test_between_time_axis(self): assert len(ts.between_time(stime, etime)) == expected_length assert len(ts.between_time(stime, etime, axis=0)) == expected_length - msg = r"No axis named 1 for object type <(class|type) 'type'>" + msg = "No axis named 1 for object type 'Series'" with pytest.raises(ValueError, match=msg): ts.between_time(stime, etime, axis=1) From 94767a53e4516278bb5e489d57c8c5005e0862cd Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 6 Mar 2019 10:14:15 +0000 Subject: [PATCH 2/4] display fully qualified path for class in error message --- pandas/core/generic.py | 8 ++++---- pandas/tests/frame/test_analytics.py | 8 ++++++-- pandas/tests/frame/test_api.py | 6 ++++-- pandas/tests/frame/test_axis_select_reindex.py | 6 ++++-- pandas/tests/frame/test_missing.py | 6 ++++-- pandas/tests/frame/test_quantile.py | 9 +++++++-- pandas/tests/frame/test_sorting.py | 6 ++++-- pandas/tests/frame/test_timeseries.py | 6 ++++-- pandas/tests/series/test_analytics.py | 4 +++- pandas/tests/series/test_missing.py | 6 ++++-- pandas/tests/series/test_rank.py | 6 ++++-- pandas/tests/series/test_sorting.py | 6 +++++- pandas/tests/series/test_timeseries.py | 6 ++++-- 13 files changed, 57 insertions(+), 26 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 836fc324ac664..8da0d14f80ef1 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -357,8 +357,8 @@ def _get_axis_number(cls, axis): return cls._AXIS_NUMBERS[axis] except KeyError: pass - raise ValueError("No axis named {0} for object type '{1}'" - .format(axis, cls.__name__)) + raise ValueError('No axis named {0} for object type {1}' + .format(axis, cls)) @classmethod def _get_axis_name(cls, axis): @@ -371,8 +371,8 @@ def _get_axis_name(cls, axis): return cls._AXIS_NAMES[axis] except KeyError: pass - raise ValueError("No axis named {0} for object type '{1}'" - .format(axis, cls.__name__)) + raise ValueError('No axis named {0} for object type {1}' + .format(axis, cls)) def _get_axis(self, axis): name = self._get_axis_name(axis) diff --git a/pandas/tests/frame/test_analytics.py b/pandas/tests/frame/test_analytics.py index 2581745d710f4..2969e8be2db03 100644 --- a/pandas/tests/frame/test_analytics.py +++ b/pandas/tests/frame/test_analytics.py @@ -1372,6 +1372,7 @@ def test_pct_change(self): # ---------------------------------------------------------------------- # Index of max / min + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_idxmin(self, float_frame, int_frame): frame = float_frame frame.loc[5:10] = np.nan @@ -1384,10 +1385,12 @@ def test_idxmin(self, float_frame, int_frame): skipna=skipna) tm.assert_series_equal(result, expected) - msg = "No axis named 2 for object type 'DataFrame'" + msg = ("No axis named 2 for object type" + " ") with pytest.raises(ValueError, match=msg): frame.idxmin(axis=2) + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_idxmax(self, float_frame, int_frame): frame = float_frame frame.loc[5:10] = np.nan @@ -1400,7 +1403,8 @@ def test_idxmax(self, float_frame, int_frame): skipna=skipna) tm.assert_series_equal(result, expected) - msg = "No axis named 2 for object type 'DataFrame'" + msg = ("No axis named 2 for object type" + " ") with pytest.raises(ValueError, match=msg): frame.idxmax(axis=2) diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 4db2078265895..badfa0ca8fd15 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -9,7 +9,7 @@ import numpy as np import pytest -from pandas.compat import long, lrange, range +from pandas.compat import PY2, long, lrange, range import pandas as pd from pandas import ( @@ -360,12 +360,14 @@ def test_transpose(self, float_frame): for col, s in compat.iteritems(mixed_T): assert s.dtype == np.object_ + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_swapaxes(self): df = self.klass(np.random.randn(10, 5)) self._assert_frame_equal(df.T, df.swapaxes(0, 1)) self._assert_frame_equal(df.T, df.swapaxes(1, 0)) self._assert_frame_equal(df, df.swapaxes(0, 0)) - msg = r"No axis named 2 for object type '(Sparse)?DataFrame'" + msg = ("No axis named 2 for object type" + r" ") with pytest.raises(ValueError, match=msg): df.swapaxes(2, 5) diff --git a/pandas/tests/frame/test_axis_select_reindex.py b/pandas/tests/frame/test_axis_select_reindex.py index f8f74b12b7990..cf8c55f00b061 100644 --- a/pandas/tests/frame/test_axis_select_reindex.py +++ b/pandas/tests/frame/test_axis_select_reindex.py @@ -7,7 +7,7 @@ import numpy as np import pytest -from pandas.compat import lrange, lzip, u +from pandas.compat import PY2, lrange, lzip, u from pandas.errors import PerformanceWarning import pandas as pd @@ -1051,6 +1051,7 @@ def test_reindex_corner(self): smaller = self.intframe.reindex(columns=['A', 'B', 'E']) assert smaller['E'].dtype == np.float64 + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_reindex_axis(self): cols = ['A', 'B', 'E'] with tm.assert_produces_warning(FutureWarning) as m: @@ -1066,7 +1067,8 @@ def test_reindex_axis(self): reindexed2 = self.intframe.reindex(index=rows) assert_frame_equal(reindexed1, reindexed2) - msg = "No axis named 2 for object type 'DataFrame'" + msg = ("No axis named 2 for object type" + " ") with pytest.raises(ValueError, match=msg): self.intframe.reindex_axis(rows, axis=2) diff --git a/pandas/tests/frame/test_missing.py b/pandas/tests/frame/test_missing.py index c491ad7aa4973..189531c7b4459 100644 --- a/pandas/tests/frame/test_missing.py +++ b/pandas/tests/frame/test_missing.py @@ -9,7 +9,7 @@ import numpy as np import pytest -from pandas.compat import lrange +from pandas.compat import PY2, lrange import pandas.util._test_decorators as td import pandas as pd @@ -83,6 +83,7 @@ def test_dropIncompleteRows(self): tm.assert_index_equal(samesize_frame.index, self.frame.index) tm.assert_index_equal(inp_frame2.index, self.frame.index) + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_dropna(self): df = DataFrame(np.random.randn(6, 4)) df[2][:2] = np.nan @@ -139,7 +140,8 @@ def test_dropna(self): assert_frame_equal(dropped, expected) # bad input - msg = "No axis named 3 for object type 'DataFrame'" + msg = ("No axis named 3 for object type" + " ") with pytest.raises(ValueError, match=msg): df.dropna(axis=3) diff --git a/pandas/tests/frame/test_quantile.py b/pandas/tests/frame/test_quantile.py index 03515705e48a8..facbfdd0c032b 100644 --- a/pandas/tests/frame/test_quantile.py +++ b/pandas/tests/frame/test_quantile.py @@ -5,6 +5,8 @@ import numpy as np import pytest +from pandas.compat import PY2 + import pandas as pd from pandas import DataFrame, Series, Timestamp from pandas.tests.frame.common import TestData @@ -71,6 +73,7 @@ def test_quantile_axis_mixed(self): with pytest.raises(TypeError): df.quantile(.5, axis=1, numeric_only=False) + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_quantile_axis_parameter(self): # GH 9543/9544 @@ -92,10 +95,12 @@ def test_quantile_axis_parameter(self): result = df.quantile(.5, axis="columns") assert_series_equal(result, expected) - msg = "No axis named -1 for object type 'DataFrame'" + msg = ("No axis named -1 for object type" + " ") with pytest.raises(ValueError, match=msg): df.quantile(0.1, axis=-1) - msg = "No axis named column for object type 'DataFrame'" + msg = ("No axis named column for object type" + " ") with pytest.raises(ValueError, match=msg): df.quantile(0.1, axis="column") diff --git a/pandas/tests/frame/test_sorting.py b/pandas/tests/frame/test_sorting.py index aaab4a0769bb9..baf50982d8ab0 100644 --- a/pandas/tests/frame/test_sorting.py +++ b/pandas/tests/frame/test_sorting.py @@ -7,7 +7,7 @@ import numpy as np import pytest -from pandas.compat import lrange +from pandas.compat import PY2, lrange import pandas as pd from pandas import ( @@ -21,6 +21,7 @@ class TestDataFrameSorting(TestData): + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_sort_values(self): frame = DataFrame([[1, 1, 2], [3, 1, 0], [4, 5, 6]], index=[1, 2, 3], columns=list('ABC')) @@ -54,7 +55,8 @@ def test_sort_values(self): sorted_df = frame.sort_values(by=['B', 'A'], ascending=[True, False]) assert_frame_equal(sorted_df, expected) - msg = "No axis named 2 for object type 'DataFrame'" + msg = ("No axis named 2 for object type" + " ") with pytest.raises(ValueError, match=msg): frame.sort_values(by=['A', 'B'], axis=2, inplace=True) diff --git a/pandas/tests/frame/test_timeseries.py b/pandas/tests/frame/test_timeseries.py index 12a75613bbeb9..9965be9091451 100644 --- a/pandas/tests/frame/test_timeseries.py +++ b/pandas/tests/frame/test_timeseries.py @@ -8,7 +8,7 @@ import pytest import pytz -from pandas.compat import product +from pandas.compat import PY2, product import pandas as pd from pandas import ( @@ -836,6 +836,7 @@ def test_datetime_assignment_with_NaT_and_diff_time_units(self): 'new': [1e9, None]}, dtype='datetime64[ns]') tm.assert_frame_equal(result, expected) + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_frame_to_period(self): K = 5 @@ -861,7 +862,8 @@ 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 'DataFrame'" + msg = ("No axis named 2 for object type" + " ") with pytest.raises(ValueError, match=msg): df.to_period(axis=2) diff --git a/pandas/tests/series/test_analytics.py b/pandas/tests/series/test_analytics.py index c87b10280ab06..d7d9c526503cb 100644 --- a/pandas/tests/series/test_analytics.py +++ b/pandas/tests/series/test_analytics.py @@ -771,6 +771,7 @@ def test_isin_empty(self, empty): result = s.isin(empty) tm.assert_series_equal(expected, result) + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_ptp(self): # GH21614 N = 1000 @@ -796,7 +797,8 @@ def test_ptp(self): with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): tm.assert_series_equal(s.ptp(level=0, skipna=False), expected) - msg = "No axis named 1 for object type 'Series'" + msg = ("No axis named 1 for object type" + " ") with pytest.raises(ValueError, match=msg): with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): diff --git a/pandas/tests/series/test_missing.py b/pandas/tests/series/test_missing.py index d21a49e68a5a4..ef9e575e60385 100644 --- a/pandas/tests/series/test_missing.py +++ b/pandas/tests/series/test_missing.py @@ -10,7 +10,7 @@ import pytz from pandas._libs.tslib import iNaT -from pandas.compat import range +from pandas.compat import PY2, range from pandas.errors import PerformanceWarning import pandas.util._test_decorators as td @@ -654,6 +654,7 @@ def test_timedelta64_nan(self): # expected = (datetime_series >= -0.5) & (datetime_series <= 0.5) # assert_series_equal(selector, expected) + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_dropna_empty(self): s = Series([]) assert len(s.dropna()) == 0 @@ -661,7 +662,8 @@ def test_dropna_empty(self): assert len(s) == 0 # invalid axis - msg = "No axis named 1 for object type 'Series'" + msg = ("No axis named 1 for object type" + " ") with pytest.raises(ValueError, match=msg): s.dropna(axis=1) diff --git a/pandas/tests/series/test_rank.py b/pandas/tests/series/test_rank.py index ab5ee11d31e49..373083c077e28 100644 --- a/pandas/tests/series/test_rank.py +++ b/pandas/tests/series/test_rank.py @@ -9,7 +9,7 @@ from pandas._libs.algos import Infinity, NegInfinity from pandas._libs.tslib import iNaT import pandas.compat as compat -from pandas.compat import product +from pandas.compat import PY2, product import pandas.util._test_decorators as td from pandas import NaT, Series, Timestamp, date_range @@ -203,10 +203,12 @@ def test_rank_categorical(self): assert_series_equal(na_ser.rank(na_option='bottom', pct=True), exp_bot) assert_series_equal(na_ser.rank(na_option='keep', pct=True), exp_keep) + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_rank_signature(self): s = Series([0, 1]) s.rank(method='average') - msg = "No axis named average for object type 'Series'" + msg = ("No axis named average for object type" + " ") with pytest.raises(ValueError, match=msg): s.rank('average') diff --git a/pandas/tests/series/test_sorting.py b/pandas/tests/series/test_sorting.py index a6dc4bc56e406..162fa4ac9ab52 100644 --- a/pandas/tests/series/test_sorting.py +++ b/pandas/tests/series/test_sorting.py @@ -5,6 +5,8 @@ import numpy as np import pytest +from pandas.compat import PY2 + from pandas import Categorical, DataFrame, IntervalIndex, MultiIndex, Series import pandas.util.testing as tm from pandas.util.testing import assert_almost_equal, assert_series_equal @@ -88,6 +90,7 @@ def test_sort_values(self): with pytest.raises(ValueError, match=msg): s.sort_values(inplace=True) + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_sort_index(self): rindex = list(self.ts.index) random.shuffle(rindex) @@ -109,7 +112,8 @@ def test_sort_index(self): sorted_series = random_order.sort_index(axis=0) assert_series_equal(sorted_series, self.ts) - msg = "No axis named 1 for object type 'Series'" + msg = ("No axis named 1 for object type" + " ") with pytest.raises(ValueError, match=msg): random_order.sort_values(axis=1) diff --git a/pandas/tests/series/test_timeseries.py b/pandas/tests/series/test_timeseries.py index c75e8b74bbe6a..b6896685dd474 100644 --- a/pandas/tests/series/test_timeseries.py +++ b/pandas/tests/series/test_timeseries.py @@ -8,7 +8,7 @@ from pandas._libs.tslib import iNaT from pandas._libs.tslibs.np_datetime import OutOfBoundsDatetime -from pandas.compat import StringIO, lrange, product +from pandas.compat import PY2, StringIO, lrange, product from pandas.errors import NullFrequencyError import pandas.util._test_decorators as td @@ -867,6 +867,7 @@ def test_between_time_formats(self): for time_string in strings: assert len(ts.between_time(*time_string)) == expected_length + @pytest.mark.skipif(PY2, reason="pytest.raises match regex fails") def test_between_time_axis(self): # issue 8839 rng = date_range('1/1/2000', periods=100, freq='10min') @@ -876,7 +877,8 @@ def test_between_time_axis(self): assert len(ts.between_time(stime, etime)) == expected_length assert len(ts.between_time(stime, etime, axis=0)) == expected_length - msg = "No axis named 1 for object type 'Series'" + msg = ("No axis named 1 for object type" + " ") with pytest.raises(ValueError, match=msg): ts.between_time(stime, etime, axis=1) From 7ef0300325439f22f23837682c765ab68ca5f86c Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 6 Mar 2019 10:24:19 +0000 Subject: [PATCH 3/4] add whatsnew --- doc/source/whatsnew/v0.25.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 5dd6ce168a0de..17866a1950535 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -254,7 +254,7 @@ Sparse Other ^^^^^ -- +- Bug in error message raised when invalid ``axis`` parameter passed (:issue:`25555`) - - From b16bc0801893c5b39cd5fa7fdd292fabe0425c81 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 6 Mar 2019 17:38:30 +0000 Subject: [PATCH 4/4] alter whatsnew entry to be specific to issue --- doc/source/whatsnew/v0.25.0.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 17866a1950535..ea08a0a6fe07b 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -196,7 +196,7 @@ Missing ^^^^^^^ - Fixed misleading exception message in :meth:`Series.missing` if argument ``order`` is required, but omitted (:issue:`10633`, :issue:`24014`). -- +- Fixed class type displayed in exception message in :meth:`DataFrame.dropna` if invalid ``axis`` parameter passed (:issue:`25555`) - MultiIndex @@ -254,7 +254,7 @@ Sparse Other ^^^^^ -- Bug in error message raised when invalid ``axis`` parameter passed (:issue:`25555`) +- - -