issues: 702373263
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
702373263 | MDU6SXNzdWU3MDIzNzMyNjM= | 4427 | assign_coords with datetime64[us] changes dtype to datetime64[ns] | 22488770 | closed | 0 | 3 | 2020-09-16T01:14:11Z | 2020-09-30T00:49:35Z | 2020-09-30T00:49:35Z | CONTRIBUTOR | What happened: When using xr.DataArray.assign_coords() to assign a new coordinate to the time dimension that is an array with dtype datetime64[us], after assigning, the dtype is datetime64[ns], resulting in the wrong dates, since the dates I am using are outside the valid range for the [ns] units. What you expected to happen: Preserve dtype of array when assigning as a coordinate. Minimal Complete Verifiable Example: ```python import numpy as np import xarray as xr import cftime tmp = np.random.random(12) da = xr.DataArray(tmp, dims='time') times=list() for mth in np.arange(1, 13): times.append(cftime.DatetimeNoLeap(1250, mth, 1)) times64 = np.array([np.datetime64(t, 'us') for t in times]) da = da.assign_coords({'time': times64})
and for the array after assigning:
Anything else we need to know?: Environment: Output of <tt>xr.show_versions()</tt>INSTALLED VERSIONS ------------------ commit: None python: 3.7.8 | packaged by conda-forge | (default, Jul 31 2020, 02:37:09) [Clang 10.0.1 ] python-bits: 64 OS: Darwin OS-release: 18.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.5 libnetcdf: 4.7.3 xarray: 0.16.0 pandas: 1.1.0 numpy: 1.19.1 scipy: 1.4.1 netCDF4: 1.5.3 pydap: installed h5netcdf: None h5py: None Nio: None zarr: None cftime: 1.0.4.2 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2.21.0 distributed: 2.22.0 matplotlib: 3.1.2 cartopy: 0.17.0 seaborn: None numbagg: None pint: None setuptools: 49.3.1.post20200810 pip: 20.2.2 conda: None pytest: None IPython: 7.17.0 sphinx: 3.2.0 |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/4427/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |