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.
There is something very odd going on here.
>>> memoryview(zeros(10, dtype=[("A", "m8[s]")]))
<memory at 0x102654348>
>>>
ValueError: cannot include dtype 'm' in a buffer
My conjecture is that this is related to https://bugs.python.org/issue23571. Some C function underlying memoryview
is both returning a non-null result and setting an error flag. This apparently causes the error to be raised when the next statement is executed! In Python 3.5, the interpreter raises a SystemError
instead when this condition occurs.
It seems like the real bug here is with the memoryview
function, not with numpy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With