OverflowError if using NaT as fill_value for mM dtypes
See original GitHub issueCode sample
import zarr
import numpy as np
z = zarr.full(dtype='m8[s]',
fill_value=np.timedelta64('nat'),
shape=10)
raises
OverflowError: int too big to convert
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/tom/anaconda3/lib/python3.6/site-packages/zarr/meta.py", line 38, in decode_array_metadata
fill_value = decode_fill_value(meta['fill_value'], dtype)
File "/home/tom/anaconda3/lib/python3.6/site-packages/zarr/meta.py", line 159, in decode_fill_value
return np.array(v, dtype=dtype)[()]
SystemError: <built-in function array> returned a result with an error set
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/tom/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2963, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-156-d1f331fc15fd>", line 6, in <module>
shape=10)
File "/home/tom/anaconda3/lib/python3.6/site-packages/zarr/creation.py", line 274, in full
return create(shape=shape, fill_value=fill_value, **kwargs)
File "/home/tom/anaconda3/lib/python3.6/site-packages/zarr/creation.py", line 123, in create
cache_metadata=cache_metadata, cache_attrs=cache_attrs, read_only=read_only)
File "/home/tom/anaconda3/lib/python3.6/site-packages/zarr/core.py", line 123, in __init__
self._load_metadata()
File "/home/tom/anaconda3/lib/python3.6/site-packages/zarr/core.py", line 140, in _load_metadata
self._load_metadata_nosync()
File "/home/tom/anaconda3/lib/python3.6/site-packages/zarr/core.py", line 155, in _load_metadata_nosync
meta = decode_array_metadata(meta_bytes)
File "/home/tom/anaconda3/lib/python3.6/site-packages/zarr/meta.py", line 50, in decode_array_metadata
raise MetadataError('error decoding metadata: %s' % e)
zarr.errors.MetadataError: error decoding metadata: <built-in function array> returned a result with an error set
Analysis
I think the serialization method for mM types does not allow to unserialize properly Not a Time fill values.
np.array(int(np.datetime64('nat').view('u8')), dtype='M8[D]')[()]
Resolution
In meta.py / encode_fill_value
:
elif dtype.kind in 'mM':
if np.isnat(v):
return 'NaT'
else:
return int(v.view('u8'))
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Release Notes — pandas 0.14.1 documentation - PyData |
This is a major release from 0.13.1 and includes a number of API changes, several new features, enhancements, and performance improvements along with...
Read more >numpy/core.py at main · numpy/numpy - GitHub
Recursively produce a fill value for `dtype`, calling f on scalar dtypes. """ if dtype.names is not None: # We wrap into `array`...
Read more >Release Notes — NumPy v1.16 Manual
Consistent with the behavior of NaN, all comparisons other than inequality checks with datetime64 or timedelta64 NaT (“not-a-time”) values ...
Read more >numpy.ma.core — CDMS Documentation
This function is useful for calculating a fill value suitable for taking the minimum of an array with a given dtype. Parameters ----------...
Read more >What's New - Xarray
Use ds.head().load() when wanting to see just a sample of the data. ... DataArrayCoordinates.dtypes properties: Mapping from variable names to dtypes.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Have PR ( https://github.com/zarr-developers/numcodecs/pull/127 ) and PR ( https://github.com/zarr-developers/zarr/pull/344 ) in the works to fix this issue.
Edit: Have verified these fix the case described in the OP. The latter PR includes a round-trip test of
NaT
as afill_value
.Closing as this should be resolved with PR ( https://github.com/zarr-developers/zarr/pull/344 ) and Numcodecs 0.6.2+. Please let us know if you run into any issues.