Skip to content

serializing not a time (NaT) to metadata #3028

Open
@d-v-b

Description

@d-v-b

Numpy datetime and timedelta dtypes have a nan-like value called NaT. The NaT value internally represented by the 64 bit signed integer -9223372036854775808:

np.int64(-9223372036854775808).view('datetime64')
# np.datetime64('NaT')

The zarr v2 spec does not define a JSON-serializable fill value encoding for datetimes or timedeltas. In lieu of a spec, we can go by the implementation of zarr-python 2.x, which used the integer form of the datetime / timedelta for all fill value, including NaT:

# /// script
# requires-python = ">=3.11"
# dependencies = [
#     "zarr==2.18",
#     "numcodecs<0.16"
# ]
# ///


import zarr
import json
z = zarr.create((10,), dtype='>M8[s]', fill_value='NaT')
print(json.loads(z.store['.zarray'])['fill_value'])
# -9223372036854775808

But we have a property test that checks if the numpy NaT value is serialized to metadata as the string "NaT". This goes against the behavior of v2, according to which It should be serialized as an int.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions