numpy/numpy — pull request #171 by larsmans (2011-11-10 13:34:37+00:00)
Title: Raise TypeError instead of NotImplementedError for wrong types

I noticed that ufuncs raise a `NotImplementedError` instead of a `TypeError` when they receive an object of the wrong type. I consider this a bug, since `NotImplementedError` is [intended](http://docs.python.org/library/exceptions.html#exceptions.NotImplementedError) to be raised by "abstract methods (...) when they require derived classes to override the method."

The enclosed patch changes the behavior to raising a `TypeError` instead. This makes exception handling a lot simpler as well, since sometimes, ufuncs would already raise a `TypeError`:

>>> from numpy import isfinite
>>> isfinite('foo')
Traceback (most recent call last):
File "", line 1, in
NotImplementedError: Not implemented for this type
>>> isfinite(None)
Traceback (most recent call last):
File "", line 1, in
TypeError: function not supported for these types, and can't coerce safely to supported types