This is a bug in lib.
dtype objects can be built dynamically. And NumPy does it all the time. There is no guarantee that they are interned, so building a dtype that already exists will give you the same thing.
Also, np.float64 is not really a dtype ; this ... I don't know what these types call, but the types used to build scalar objects from the bytes of the array, which are usually found in the type dtype attribute, so I'm going to call this a dtype.type . (Note that np.float64 subclasses both NumPy numeric tower types and ABC with a Python numeric tower, while np.dtype , of course not.)
You can usually use them interchangeably; when you use dtype.type or, for that matter, the native Python numeric type where dtype was expected, and dtype is built on the fly (which, again, is not guaranteed to be interned), but of course that doesnβt mean that they are identical:
>>> np.float64 == np.dtype(np.float64) == np.dtype('float64') True >>> np.float64 == np.dtype(np.float64).type True
dtype.type will usually be identical if you use the built-in types:
>>> np.float64 is np.dtype(np.float64).type True
But two dtype are often missing:
>>> np.dtype(np.float64) is np.dtype('float64') False
But again, none of this is guaranteed. (Also, note that np.float64 and float use the same storage, but are separate types. And of course, you can also make dtype('f8') , which is guaranteed to work the same way dtype(np.float64) , but that doesn't mean 'f8' is or even == , np.float64 .)
Thus, it is possible that building an array by explicitly passing np.float64 as the dtype argument means that you will return the same instance when you check the dtype.type attribute, but this is not guaranteed. And if you pass np.dtype('float64') or ask NumPy to output it from the data, or you pass a dtype string to parse it, e.g. 'f8' , etc., It will be less likely. More importantly, you definitely will not get np.float64 back as dtype .
So how should this be fixed?
Well, the docs define what it means that the two dtype are equal, and this is a useful thing, and I think this is probably the useful thing you are looking for here. So just replace is with == :
if isinstance(xx_, numpy.ndarray) and xx_.dtype == numpy.float64 and xx_.flags.contiguous:
However, to some extent, I only assume that you are looking. (The fact that he checks the adjacent flag implies that he will probably go into internal storage ... but then why doesn't he check the order of C or Fortran, the order of bytes, or something else?)