Inconsitent treatment of datetime64 data between DataArray and Dask array
Open
Nobody has claimed this yet.
needs triage
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
What is your issue?
When processing datetime as the data of a DataArray, Xarray could lead to different results depending on whether the data is a numpy.array or a Dask.array.Array:
import dask.array
import numpy as np
import xarray as xr
data = np.array("2016-01-01").astype("datetime64[s]")
da1 = xr.DataArray(data)
da2 = xr.DataArray(dask.array.from_array(data))
assert da1.equals(da2)
assert da1.astype("datetime64[M]").dtype == '<M8[s]'
assert da2.astype("datetime64[M]").dtype == '<M8[M]'
assert da1.astype("datetime64[M]").astype(int).data == 1451606400
assert da2.astype("datetime64[M]").astype(int).compute().data == 552
Environment info:
- xarray 2025.7.1
- dask 2025.7.0
Issue opened after @spencerkclark comment in #10220
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the Python reproducer in the issue with NumPy-backed and Dask-backed DataArray objects, then trace the astype calls involved in datetime64 conversion. Compare the resulting dtypes and integer values, and add a regression test wherever the relevant behavior is covered. Done means both paths have an agreed, consistent result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100