[Numpy-discussion] dtype subarray comparison
Wed Oct 20 18:59:53 CDT 2010
It turns out that when comparing dtypes, the subarray is currently ignored.
This means you can get things like this:
>>> import numpy as np
>>> np.dtype(('f4',(6))) == np.dtype(('f4',(2,3)))
>>> np.dtype(([('a','i4')],2)) == np.dtype(([('b','u2'),('c','i2')],2))
which pretty clearly should be False in both cases. I've implemented a
patch to fix this, for which a pull request is here:
The main points included in this patch are:
* If there's a subarray shape, it has to match exactly.
* Currently, sometimes the subarray shape was an integer, other times a
tuple. The output formatting code checks for this and prints a tuple in
both cases. I changed the code to turn the integer into a tuple on
construction instead. This didn't cause any tests to fail, so I think it's
a safe change.
* The current code converts (type, 1) and (type, tuple()) to just type, so
this means (type, 1) != (type, (1,)) but (type, 2) == (type, (2,)) I put in
some tests of these edge cases.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion