[Numpy-discussion] how can one catch a multiarray.error

josef.pktd@gmai... josef.pktd@gmai...
Tue Jun 2 21:36:58 CDT 2009


On Tue, Jun 2, 2009 at 10:25 PM, Robert Kern <robert.kern@gmail.com> wrote:
> On Tue, Jun 2, 2009 at 21:20, Charles R Harris
> <charlesr.harris@gmail.com> wrote:
>>
>>
>> On Mon, Jun 1, 2009 at 8:43 PM, Robert Kern <robert.kern@gmail.com> wrote:
>>>
>>> On Mon, Jun 1, 2009 at 21:37,  <josef.pktd@gmail.com> wrote:
>>> > how do we catch a multiarray.error in a try except clause?
>>> >
>>> > e.g.
>>> >>>> np.argmin([])
>>> > Traceback (most recent call last):
>>> >  File "<pyshell#147>", line 1, in <module>
>>> >    np.argmin([])
>>> >  File
>>> > "C:\Programs\Python25\Lib\site-packages\numpy\core\fromnumeric.py",
>>> > line 631, in argmin
>>> >    return _wrapit(a, 'argmin', axis)
>>> >  File
>>> > "C:\Programs\Python25\Lib\site-packages\numpy\core\fromnumeric.py",
>>> > line 37, in _wrapit
>>> >    result = getattr(asarray(obj),method)(*args, **kwds)
>>> > multiarray.error: attempt to get argmax/argmin of an empty sequence
>>>
>>> try:
>>>   ...
>>> except numpy.core.multiarray.error:
>>>   ...
>>>
>>> Unfortunately, that is still a string exception. We should change that.
>>
>> I'm fixing these, but doesn't that constitute an abi change? Code that used
>> to catch the exceptions won't anymore.
>
> If they are catching numpy.core.multiarray.error, then it's not a
> problem. They never should have been catching "multiarray.error".
>

But in my example it was the only way that I found to catch this
error, except with an empty except clause. So someone might have also
used it this way. I guess this would be an API change in my example.

Josef


More information about the Numpy-discussion mailing list