Skip to content

Commit d0d2d93

Browse files
committed
Cast datetime and timedelta to signed 64-bit int
The `NaT` type is represented as `-0`. As a result, casting to an unsigned integral fails and throws an error. However casting to a signed integral type does not have this problem and proceeds without issues.
1 parent bea4b32 commit d0d2d93

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

numcodecs/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,5 @@ def ensure_text(l, encoding='utf-8'):
102102

103103
def handle_datetime(buf):
104104
if hasattr(buf, 'dtype') and buf.dtype.kind in 'Mm':
105-
return buf.view('u8')
105+
return buf.view('i8')
106106
return buf

numcodecs/compat_ext.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cdef class Buffer:
2121
self.released = False
2222
if hasattr(obj, 'dtype'):
2323
if obj.dtype.kind in 'Mm':
24-
obj = obj.view('u8')
24+
obj = obj.view('i8')
2525
elif obj.dtype.kind == 'O':
2626
raise ValueError('cannot obtain buffer from object array')
2727
if PY2 and isinstance(obj, array.array):

0 commit comments

Comments
 (0)