@@ -1620,10 +1620,10 @@ def test_roundtrip_float_times(fill_value, times, units, encoded_values) -> None
1620
1620
_ENCODE_DATETIME64_VIA_DASK_TESTS .values (),
1621
1621
ids = _ENCODE_DATETIME64_VIA_DASK_TESTS .keys (),
1622
1622
)
1623
- def test_encode_cf_datetime_datetime64_via_dask (freq , units , dtype ) -> None :
1623
+ def test_encode_cf_datetime_datetime64_via_dask (freq , units , dtype , time_unit ) -> None :
1624
1624
import dask .array
1625
1625
1626
- times_pd = pd .date_range (start = "1700" , freq = freq , periods = 3 )
1626
+ times_pd = pd .date_range (start = "1700" , freq = freq , periods = 3 , unit = time_unit )
1627
1627
times = dask .array .from_array (times_pd , chunks = 1 )
1628
1628
encoded_times , encoding_units , encoding_calendar = encode_cf_datetime (
1629
1629
times , units , None , dtype
@@ -1636,13 +1636,17 @@ def test_encode_cf_datetime_datetime64_via_dask(freq, units, dtype) -> None:
1636
1636
assert encoding_units == units
1637
1637
assert encoded_times .dtype == dtype
1638
1638
else :
1639
- assert encoding_units == "nanoseconds since 1970-01-01"
1639
+ expected_netcdf_time_unit = _numpy_to_netcdf_timeunit (time_unit )
1640
+ assert encoding_units == f"{ expected_netcdf_time_unit } since 1970-01-01"
1640
1641
assert encoded_times .dtype == np .dtype ("int64" )
1641
1642
1642
1643
assert encoding_calendar == "proleptic_gregorian"
1643
1644
1644
- decoded_times = decode_cf_datetime (encoded_times , encoding_units , encoding_calendar )
1645
+ decoded_times = decode_cf_datetime (
1646
+ encoded_times , encoding_units , encoding_calendar , time_unit = time_unit
1647
+ )
1645
1648
np .testing .assert_equal (decoded_times , times )
1649
+ assert decoded_times .dtype == times .dtype
1646
1650
1647
1651
1648
1652
@requires_dask
@@ -1749,11 +1753,11 @@ def test_encode_cf_datetime_casting_overflow_error(use_cftime, use_dask, dtype)
1749
1753
("units" , "dtype" ), [("days" , np .dtype ("int32" )), (None , None )]
1750
1754
)
1751
1755
def test_encode_cf_timedelta_via_dask (
1752
- units : str | None , dtype : np .dtype | None
1756
+ units : str | None , dtype : np .dtype | None , time_unit : PDDatetimeUnitOptions
1753
1757
) -> None :
1754
1758
import dask .array
1755
1759
1756
- times_pd = pd .timedelta_range (start = "0D" , freq = "D" , periods = 3 )
1760
+ times_pd = pd .timedelta_range (start = "0D" , freq = "D" , periods = 3 , unit = time_unit )
1757
1761
times = dask .array .from_array (times_pd , chunks = 1 )
1758
1762
encoded_times , encoding_units = encode_cf_timedelta (times , units , dtype )
1759
1763
@@ -1764,11 +1768,14 @@ def test_encode_cf_timedelta_via_dask(
1764
1768
assert encoding_units == units
1765
1769
assert encoded_times .dtype == dtype
1766
1770
else :
1767
- assert encoding_units == "nanoseconds"
1771
+ assert encoding_units == _numpy_to_netcdf_timeunit ( time_unit )
1768
1772
assert encoded_times .dtype == np .dtype ("int64" )
1769
1773
1770
- decoded_times = decode_cf_timedelta (encoded_times , encoding_units )
1774
+ decoded_times = decode_cf_timedelta (
1775
+ encoded_times , encoding_units , time_unit = time_unit
1776
+ )
1771
1777
np .testing .assert_equal (decoded_times , times )
1778
+ assert decoded_times .dtype == times .dtype
1772
1779
1773
1780
1774
1781
@pytest .mark .parametrize ("use_dask" , [False , pytest .param (True , marks = requires_dask )])
0 commit comments