Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should just be cls as it gives the fully qualified path

raise ValueError("No axis named {0} for object type '{1}'"
.format(axis, cls.__name__))

@classmethod
def _get_axis_name(cls, axis):
Expand All @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions pandas/tests/frame/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <class '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
Expand All @@ -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 <class 'type'>"
msg = "No axis named 2 for object type 'DataFrame'"
with pytest.raises(ValueError, match=msg):
frame.idxmax(axis=2)

Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 <class 'type'>"
msg = r"No axis named 2 for object type '(Sparse)?DataFrame'"
with pytest.raises(ValueError, match=msg):
df.swapaxes(2, 5)

Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/frame/test_axis_select_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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 <class 'type'>"
msg = "No axis named 2 for object type 'DataFrame'"
with pytest.raises(ValueError, match=msg):
self.intframe.reindex_axis(rows, axis=2)

Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/frame/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -140,7 +139,7 @@ def test_dropna(self):
assert_frame_equal(dropped, expected)

# bad input
msg = "No axis named 3 for object type <class 'type'>"
msg = "No axis named 3 for object type 'DataFrame'"
with pytest.raises(ValueError, match=msg):
df.dropna(axis=3)

Expand Down
7 changes: 2 additions & 5 deletions pandas/tests/frame/test_quantile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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 <class '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 <class 'type'>"
msg = "No axis named column for object type 'DataFrame'"
with pytest.raises(ValueError, match=msg):
df.quantile(0.1, axis="column")

Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/frame/test_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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'))
Expand Down Expand Up @@ -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 <class '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)

Expand Down
5 changes: 2 additions & 3 deletions pandas/tests/frame/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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

Expand All @@ -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 <class 'type'>"
msg = "No axis named 2 for object type 'DataFrame'"
with pytest.raises(ValueError, match=msg):
df.to_period(axis=2)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_rank.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down