home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 584865241

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
584865241 MDU6SXNzdWU1ODQ4NjUyNDE= 3872 Operations resulting in np.timedelta64 are not properly coerced 33886395 closed 0     2 2020-03-20T06:14:30Z 2020-03-23T20:55:54Z 2020-03-23T20:55:53Z NONE      

It seems that operations that are resulting in timedelta64 (for example datetime64 arithmetic) are not properly coerced. In fact, the result of that operation is a xarray object that has a dt accessor being of type xarray.core.accessor_dt.DatetimeAccessor instead of the expected xarray.core.accessor_dt.TimedeltaAccessor

This follows the numpy documentation describing datetime arithmentic resulting in timedelta objects (http://lagrange.univ-lyon1.fr/docs/numpy/1.11.0/reference/arrays.datetime.html#datetime-and-timedelta-arithmetic)

MCVE Code Sample

```python

this is a DataArray of type np.datetime64

da = xr.DataArray( data= pd.date_range('2020-01-01', '2020-01-30', freq='D') )

this simple arithmetic will result in np.timedelta64

delta = (da - np.datetime64('2020-01-01'))

type(delta.data[0])

> numpy.timedelta64

type(delta.dt)

> xarray.core.accessor_dt.DatetimeAccessor

```

Expected Output

```python type(delta.dt)

> xarray.core.accessor_dt.TimedeltaAccessor

```

Problem Description

Having a .data of type timedelta64 would benefit from having a .dt accessor of type TimedeltaAccessor. This would allow to represent such timedelta64 using the relevant time units like days

Versions

Output of `xr.show_versions()` INSTALLED VERSIONS ------------------ commit: None python: 3.6.10 | packaged by conda-forge | (default, Mar 5 2020, 10:05:08) [GCC 7.3.0] python-bits: 64 OS: Linux OS-release: 4.12.14-95.32-default machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.4 libnetcdf: 4.6.2 xarray: 0.14.1 pandas: 0.24.1 numpy: 1.18.1 scipy: 1.4.1 netCDF4: 1.5.1.2 pydap: None h5netcdf: 0.8.0 h5py: 2.9.0 Nio: None zarr: 2.2.0 cftime: 1.0.4.2 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: 1.3.2 dask: 2.12.0 distributed: 2.12.0 matplotlib: 3.0.3 cartopy: None seaborn: 0.10.0 numbagg: None setuptools: 45.2.0.post20200209 pip: 20.0.2 conda: None pytest: None IPython: 7.13.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/3872/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

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