Pythons memoryview does not support datetime64 or timedelta. Ok. But when I try to create a memoryview of a structured array that includes a datetime64 or timedelta, it appears to work... unless I assign it to a variable!
In [19]: memoryview(zeros(10, dtype=[("A", "m8[s]")]))
Out[19]: <memory at 0x7f1d455d6048>
In [20]: x = memoryview(zeros(10, dtype=[("A", "m8[s]")]))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
ValueError: cannot include dtype 'm' in a buffer
In [21]: x = _19
In [22]: x
Out[22]: <memory at 0x7f1d455d6048>
This seriously challenges my understanding of the way Python fundamentally works. How can f() and x = f() be different, considering that (1) IPythons REPL assigns the output to _19 anyway, and (2) the function/class memoryview has no way of knowing what the caller is going to do with its output?
I am running the code on Python 3.4.1, numpy 1.10.0.dev+fbcc24f, on Linux 2.6.32-431.23.3.el6.x86_64, Scientific Linux release 6.6.
EDIT
On Python 3.5, numpy 1.10.4, I get:
In [50]: memoryview(numpy.zeros(10, dtype=[("A", "m8[s]")]))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
ValueError: cannot include dtype 'm' in a buffer
During handling of the above exception, another exception occurred:
SystemError Traceback (most recent call last)
<ipython-input-50-5d5ac6c085fa> in <module>()
----> 1 memoryview(numpy.zeros(10, dtype=[("A", "m8[s]")]))
SystemError: <class 'memoryview'> returned a result with an error set
I have filed a bug with numpy, although I'm not quite sure that's where the problem lies.