[Numpy-discussion] TypeError in dtype.__eq__()
Sun Jan 11 03:41:31 CST 2009
Dtype objects throw an exception if compared for equality against other
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: data type not understood
After some googling, I think python wisdom (given in the Python docs)
says that equality testing should never throw an exception, but return
the NotImplemented singleton where the comparison does not make "sense".
Throwing an exception breaks membership testing for lists/tuples (using
the 'in' operator calls implicitly calls __eq__()).
My real-world example is serialisation of numpy arrays using PyYAML.
This module should serialise any picklable object including ndarrays.
However, it performs a test on each object:
if data in [None, ()]: blah...
This fails on the dtype object of the array.
What's the consensus on this? Is the current dtype behaviour broken?
More information about the Numpy-discussion