home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 1232587833

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
1232587833 I_kwDOAMm_X85Jd8w5 6591 Xarray ignores the underlying unit of "datetime64" types. 12649253 open 0     2 2022-05-11T12:48:36Z 2022-08-22T12:53:22Z   NONE      

What happened?

xarray always converts "datetime64" types to nanoseconds.

xarray also silently does nothing when calling .astype('datetime64[ms]') on an datetime64 type.

What did you expect to happen?

I would expect the same behavior as in numpy (respect units, as shown in the reproducer). Or at least raise an error, when calling astype with a different unit.

Minimal Complete Verifiable Example

```Python import numpy as np import xarray as xa

As expected.

time_array = np.array(["2000-01-01"]).astype('datetime64[ms]') print(time_array.dtype) # datetime64[ms] print(time_array.astype('datetime64[s]').dtype) # datetime64[s]

Always end up with "ns".

time_data_array = xa.DataArray(data=time_array, dims=("time")) print(time_data_array.dtype) # datetime64[ns] print(time_data_array.astype('datetime64[s]').dtype) # datetime64[ns]

MVCE confirmation

  • [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • [X] Complete example — the example is self-contained, including all data and the text of any traceback.
  • [X] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • [X] New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

No response

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.7.13 (default, Apr 24 2022, 01:04:09) [GCC 7.5.0] python-bits: 64 OS: Linux OS-release: 5.4.188+ machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.0 libnetcdf: 4.7.4 xarray: 0.18.2 pandas: 1.3.5 numpy: 1.21.6 scipy: 1.4.1 netCDF4: 1.5.8 pydap: None h5netcdf: None h5py: 3.1.0 Nio: None zarr: None cftime: 1.6.0 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: 1.3.4 dask: 2.12.0 distributed: 1.25.3 matplotlib: 3.2.2 cartopy: None seaborn: 0.11.2 numbagg: None pint: None setuptools: 57.4.0 pip: 21.1.3 conda: None pytest: 3.6.4 IPython: 5.5.0 sphinx: 1.8.6
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/6591/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

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