diff --git a/doc/source/release.rst b/doc/source/release.rst index 5db612059685b..5b6a0d15be943 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -317,10 +317,11 @@ API Changes - Arithemtic func factories are now passed real names (suitable for using with super) (:issue:`5240`) - Provide numpy compatibility with 1.7 for a calling convention like ``np.prod(pandas_object)`` as numpy call with additional keyword args (:issue:`4435`) - - Provide __dir__ method (and local context) for tab completion / remove ipython completers code - (:issue:`4501`) + - Provide ``__dir__`` method (and local context) for tab completion / remove + ipython completers code (:issue:`4501`) - Support non-unique axes in a Panel via indexing operations (:issue:`4960`) - ``.truncate`` will raise a ``ValueError`` if invalid before and afters dates are given (:issue:`5242`) + - Improve some exceptions in core/generic. (:issue:`5051`) Internal Refactoring ~~~~~~~~~~~~~~~~~~~~ diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 9666fe42cc822..100c546753154 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -233,8 +233,8 @@ def _construct_axes_from_arguments(self, args, kwargs, require_all=False): if alias is not None: if a in kwargs: if alias in kwargs: - raise Exception( - "arguments are multually exclusive for [%s,%s]" % (a, alias)) + raise TypeError("arguments are multually exclusive " + "for [%s,%s]" % (a, alias)) continue if alias in kwargs: kwargs[a] = kwargs.pop(alias) @@ -244,10 +244,9 @@ def _construct_axes_from_arguments(self, args, kwargs, require_all=False): if a not in kwargs: try: kwargs[a] = args.pop(0) - except (IndexError): + except IndexError: if require_all: - raise AssertionError( - "not enough arguments specified!") + raise TypeError("not enough arguments specified!") axes = dict([(a, kwargs.get(a)) for a in self._AXIS_ORDERS]) return axes, kwargs @@ -273,7 +272,8 @@ def _get_axis_number(self, axis): return self._AXIS_NUMBERS[axis] except: pass - raise ValueError('No axis named {0} for object type {1}'.format(axis,type(self))) + raise ValueError('No axis named {0} for object type {1}'.format( + axis, type(self).__name__)) def _get_axis_name(self, axis): axis = self._AXIS_ALIASES.get(axis, axis) @@ -285,7 +285,8 @@ def _get_axis_name(self, axis): return self._AXIS_NAMES[axis] except: pass - raise ValueError('No axis named {0} for object type {1}'.format(axis,type(self))) + raise ValueError('No axis named {0} for object type {1}'.format( + axis, type(self).__name__)) def _get_axis(self, axis): name = self._get_axis_name(axis) diff --git a/pandas/tests/test_panel.py b/pandas/tests/test_panel.py index 07b33266d88a1..7b5e6ac2dd1cf 100644 --- a/pandas/tests/test_panel.py +++ b/pandas/tests/test_panel.py @@ -1250,12 +1250,19 @@ def test_transpose(self): ## test bad aliases # test ambiguous aliases - self.assertRaises(AssertionError, self.panel.transpose, 'minor', - maj='major', majo='items') + with tm.assertRaisesRegexp(TypeError, 'not enough arguments'): + self.panel.transpose('minor', maj='major', majo='items') # test invalid kwargs - self.assertRaises(AssertionError, self.panel.transpose, 'minor', - maj='major', minor='items') + # TODO: Decide whether to remove this test - it's no longer testing + # the correct thing on current master (and hasn't been for a + # while) + with tm.assertRaisesRegexp(TypeError, 'not enough arguments'): + self.panel.transpose('minor', maj='major', minor='items') + + # does this test make sense? + # with tm.assertRaisesRegexp(ValueError, 'duplicate axes'): + # self.panel.transpose('minor', 'major', major='minor', minor='items') result = self.panel.transpose(2, 1, 0) assert_panel_equal(result, expected)