Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/zarr/core/dtype/npy/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def default_scalar(self) -> np.timedelta64:
This method provides a default value for the timedelta64 scalar, which is
a 'Not-a-Time' (NaT) value.
"""
return np.timedelta64("NaT")
return np.timedelta64("NaT", self.unit)

def from_json_scalar(self, data: JSON, *, zarr_format: ZarrFormat) -> np.timedelta64:
"""
Expand Down
8 changes: 7 additions & 1 deletion tests/test_dtype/test_npy/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class TestTimeDelta64(_TestTimeBase):

cast_value_params = (
(TimeDelta64(unit="ns", scale_factor=1), "1", np.timedelta64(1, "ns")),
(TimeDelta64(unit="ns", scale_factor=1), "NaT", np.timedelta64("NaT")),
(TimeDelta64(unit="ns", scale_factor=1), "NaT", np.timedelta64("NaT", "ns")),
)
invalid_scalar_params = (
(TimeDelta64(unit="Y", scale_factor=1), 1.3),
Expand Down Expand Up @@ -148,6 +148,12 @@ def test_time_scale_factor_too_low() -> None:
TimeDelta64(scale_factor=scale_factor)


def test_default_is_NaT() -> None:
np.testing.assert_equal(
TimeDelta64(unit="ns", scale_factor=1).default_scalar(), np.timedelta64("NaT", "ns")
)


def test_time_scale_factor_too_high() -> None:
"""
Test that an invalid unit raises a ValueError.
Expand Down
Loading