[Numpy-discussion] bug with mmap'ed datetime64 arrays

Charles G. Waldman charles at crunch.io
Mon Feb 17 22:18:08 EST 2014

test case:

#!/usr/bin/env python
import numpy as np
a=np.array(['2014', '2015', '2016'], dtype='datetime64')
print a>x
np.save('test.npy', a)
b = np.load('test.npy', mmap_mode='c')
print b>x


>>> [False False  True]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/t.py", line 12, in <module>
    print b>x
  File "/usr/lib64/python2.7/site-packages/numpy/core/memmap.py", line
279, in __array_finalize__
    if hasattr(obj, '_mmap') and np.may_share_memory(self, obj):
  File "/usr/lib64/python2.7/site-packages/numpy/lib/utils.py", line
298, in may_share_memory
    a_low, a_high = byte_bounds(a)
  File "/usr/lib64/python2.7/site-packages/numpy/lib/utils.py", line
258, in byte_bounds
    bytes_a = int(ai['typestr'][2:])
ValueError: invalid literal for int() with base 10: '8[Y]'

diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py
index 1f1cdfc..c73f2f1 100644
--- a/numpy/lib/utils.py
+++ b/numpy/lib/utils.py
@@ -210,7 +210,7 @@ def byte_bounds(a):
     a_data = ai['data'][0]
     astrides = ai['strides']
     ashape = ai['shape']
-    bytes_a = int(ai['typestr'][2:])
+    bytes_a = a.dtype.itemsize

     a_low = a_high = a_data
     if astrides is None: # contiguous case

will submit pull request via github

More information about the NumPy-Discussion mailing list