home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 386596872

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
386596872 MDU6SXNzdWUzODY1OTY4NzI= 2587 DataArray constructor still coerces to np.datetime64[ns], not cftime in 0.11.0 13662783 open 0     3 2018-12-02T20:34:36Z 2022-04-18T16:06:12Z   CONTRIBUTOR      

Code Sample

```python import xarray as xr import numpy as np from datetime import datetime

time = [np.datetime64(datetime.strptime("10000101", "%Y%m%d"))] print(time[0]) print(np.dtype(time[0]))

da = xr.DataArray(time, ("time",), {"time":time}) print(da) Results in: 1000-01-01T00:00:00.000000 datetime64[us]

<xarray.DataArray (time: 1)> array(['2169-02-08T23:09:07.419103232'], dtype='datetime64[ns]') Coordinates: * time (time) datetime64[ns] 2169-02-08T23:09:07.419103232 ```

Problem description

I was happy to see cftime as default in the release notes for 0.11.0:

Xarray will now always use cftime.datetime objects, rather than by default trying to coerce them into np.datetime64[ns] objects. A CFTimeIndex will be used for indexing along time coordinates in these cases.

However, it seems that the DataArray constructor does not use cftime (yet?), and coerces to np.datetime64[ns] here: https://github.com/pydata/xarray/blob/0d6056e8816e3d367a64f36c7f1a5c4e1ce4ed4e/xarray/core/variable.py#L183-L189

Expected Output

I think I'd expect cftime.datetime in this case as well. Some coercion happens anyway as pandas timestamps are turned into np.datetime64[ns].

(But perhaps this was already on your radar, and am I just a little too eager!)

Output of xr.show_versions()

``` INSTALLED VERSIONS ------------------ commit: None python: 3.6.5.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: en LOCALE: None.None xarray: 0.11.0 pandas: 0.23.3 numpy: 1.15.3 scipy: 1.1.0 netCDF4: 1.3.1 h5netcdf: 0.6.1 h5py: 2.8.0 Nio: None zarr: None cftime: 1.0.0 PseudonetCDF: None rasterio: 1.0.0 iris: None bottleneck: 1.2.1 cyordereddict: None dask: 0.19.2 distributed: 1.23.2 matplotlib: 2.2.2 cartopy: 0.16.0 seaborn: 0.9.0 setuptools: 40.5.0 pip: 18.1 conda: None pytest: 3.6.3 IPython: 6.4.0 sphinx: 1.7.5 ```
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/2587/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    13221727 issue

Links from other tables

  • 2 rows from issues_id in issues_labels
  • 3 rows from issue in issue_comments
Powered by Datasette · Queries took 1.318ms · About: xarray-datasette