[Numpy-discussion] nanargmax failure case (was: Re: [SciPy-Dev] 1.8.0rc1)

Nathaniel Smith njs at pobox.com
Tue Oct 1 16:58:23 EDT 2013

whoops, fat-fingered this out while in the middle of typing it

On Tue, Oct 1, 2013 at 9:55 PM, Nathaniel Smith <njs at pobox.com> wrote:
> Spitball of a proper solution, though some thought would need to go
> into how to get this out of gufuncs. (And absolutely unsuitable for
> 1.8!):
> class VectorizedError(object):
>     pass
> def vectorized_raise(result, good_mask, exceptions):
>     exc_types = set([type(e) for e in exceptions])
>     exc_types.add(VectorizedError)
>     exc_type = type.__new__(type, "SubVectorizedError", tuple(exc_types), {})
>     exc = exc_type("

    # FIXME: use some heuristics to look at the exception messages and try to
    # say something more useful here
    exc = exc_type("Multiple errors")
    exc.result = result
    exc.good_mask = good_mask
    exc.exceptions = exceptions
    raise exc

Okay, maybe that's a little ridiculous, but, you know. Discuss :-).
(The black magic at the beginning is to ensure that if you have a
ValueError and a TypeError consolidated into a single VectorizedError,
then the exception that is raised can be caught by code that's looking
for a ValueError, a TypeError, *or* a VectorizedError.)


More information about the NumPy-Discussion mailing list