issues: 830256796
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
830256796 | MDU6SXNzdWU4MzAyNTY3OTY= | 5026 | Datetime accessor fails on cftime arrays with missing values | 20629530 | open | 0 | 0 | 2021-03-12T16:05:43Z | 2021-04-19T02:41:00Z | CONTRIBUTOR | What happened:
I have a computation that output dates but that sometimes also outputs missing data. (It computes the start date of a run in a timeseries, if there is no run, it outputs NaN). Afterwards, I'd like to convert those dates to dayofyear, thus I call What you expected to happen:
I expected Minimal Complete Verifiable Example: ```python import xarray as xr import numpy as np da = xr.DataArray( [[np.nan, np.nan], [1, 2]], dims=('x', 'time'), coords={'x': [1, 2], 'time': xr.cftime_range('2000-01-01', periods=2)}, ) out is a "object" array, where the first element is NaNout = da.idxmin('time') out.dt.dayofyear Expected : [nan, 1.]
TypeError Traceback (most recent call last) <ipython-input-56-06aa9bdfd6b8> in <module> ----> 1 da.idxmin('time').dt.dayofyear ~/.conda/envs/xclim-dev/lib/python3.8/site-packages/xarray/core/utils.py in get(self, obj, cls) 917 return self._accessor 918 --> 919 return self._accessor(obj) 920 921 ~/.conda/envs/xclim-dev/lib/python3.8/site-packages/xarray/core/accessor_dt.py in new(cls, obj) 514 # do all the validation here. 515 if not _contains_datetime_like_objects(obj): --> 516 raise TypeError( 517 "'.dt' accessor only available for " 518 "DataArray with datetime64 timedelta64 dtype or " TypeError: '.dt' accessor only available for DataArray with datetime64 timedelta64 dtype or for arrays containing cftime datetime objects. ``` Anything else we need to know?:
This also triggers computation when The laziness of it aside, would it be meaningful to change:
https://github.com/pydata/xarray/blob/d4b7a608bab0e7c140937b0b59ca45115d205145/xarray/core/common.py#L1822
to cycle on the array Environment: Output of <tt>xr.show_versions()</tt>INSTALLED VERSIONS ------------------ commit: None python: 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 16:22:27) [GCC 9.3.0] python-bits: 64 OS: Linux OS-release: 5.10.16-arch1-1 machine: x86_64 processor: byteorder: little LC_ALL: None LANG: fr_CA.utf8 LOCALE: fr_CA.UTF-8 libhdf5: 1.10.6 libnetcdf: 4.7.4 xarray: 0.17.0 pandas: 1.0.3 numpy: 1.18.1 scipy: 1.4.1 netCDF4: 1.5.4 pydap: None h5netcdf: None h5py: None Nio: None zarr: 2.4.0 cftime: 1.3.1 nc_time_axis: 1.2.0 PseudoNetCDF: None rasterio: 1.2.1 cfgrib: None iris: None bottleneck: 1.3.2 dask: 2.12.0 distributed: 2.20.0 matplotlib: 3.3.4 cartopy: None seaborn: None numbagg: None pint: 0.16.1 setuptools: 49.6.0.post20210108 pip: 21.0.1 conda: None pytest: 5.4.3 IPython: 7.21.0 sphinx: 3.1.2 |
{ "url": "https://api.github.com/repos/pydata/xarray/issues/5026/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
13221727 | issue |