diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-03-26 00:08:17 +0000 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-03-28 20:44:34 +0100 |
commit | 7bf911585d7f9d56480ee1b3d70fab39fc588350 (patch) | |
tree | 13204d10dba18e2437396c9022161c88020f8ddd /numpy/core/_internal.py | |
parent | ee8ce2438e8a089a06d2c8e99518df8f638afb29 (diff) | |
download | numpy-7bf911585d7f9d56480ee1b3d70fab39fc588350.tar.gz |
ENH: Allow AxisErrors to have a prefix on the message
Moving the string formatting to python makes this a lot easier
Diffstat (limited to 'numpy/core/_internal.py')
-rw-r--r-- | numpy/core/_internal.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py index 11a13026b..f25159d8e 100644 --- a/numpy/core/_internal.py +++ b/numpy/core/_internal.py @@ -631,4 +631,17 @@ class TooHardError(RuntimeError): pass class AxisError(ValueError, IndexError): - pass + """ Axis supplied was invalid. """ + def __init__(self, axis, ndim=None, msg_prefix=None): + # single-argument form just delegates to base class + if ndim is None and msg_prefix is None: + msg = axis + + # do the string formatting here, to save work in the C code + else: + msg = ("axis {} is out of bounds for array of dimension {}" + .format(axis, ndim)) + if msg_prefix is not None: + msg = "{}: {}".format(msg_prefix, msg) + + super(AxisError, self).__init__(msg) |