pydata / pydata/xarray

Inconsitent treatment of datetime64 data between DataArray and Dask array

Open
#10,673 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.