Skip to content

CLN: Fixups to exceptions in generic #5051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~~~~~~~~~~
Expand Down
15 changes: 8 additions & 7 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
15 changes: 11 additions & 4 deletions pandas/tests/test_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so what about this test and the previous? Can we just get rid of them?...they're pretty strange (and don't actually work in master for their original purpose)

Copy link
Contributor

Choose a reason for hiding this comment

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

what do you mean, it is testing if their are enough arguments and is raising an error appropriately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jreback what i mean is that the first should really be 'duplicate axes' and not 'not enough arguments' given that positional argument is supposed to reflect the minor axis but those were the assertion errors they previously generated. I don't really care either way, what do you want to do?


result = self.panel.transpose(2, 1, 0)
assert_panel_equal(result, expected)
Expand Down