html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,performed_via_github_app,issue https://github.com/pydata/xarray/issues/1565#issuecomment-883607729,https://api.github.com/repos/pydata/xarray/issues/1565,883607729,IC_kwDOAMm_X840qsix,5635139,2021-07-20T18:33:29Z,2021-07-20T18:33:29Z,MEMBER,@hding1981 you would need to make a MCVE like this: https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports in a new issue. It's unlikely someone can help you debug your data.,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,256496917 https://github.com/pydata/xarray/issues/1565#issuecomment-883603251,https://api.github.com/repos/pydata/xarray/issues/1565,883603251,IC_kwDOAMm_X840qrcz,87719516,2021-07-20T18:26:08Z,2021-07-20T18:26:08Z,NONE,"I am calculating monthly mean anomalies from a CMIP6 file, which is attached and ended by .docx (Please remove .docx from its name after downloading it). This file has reasonable time coordinate, which has been confirmed by ncdump and cdo. But it shows NaT after a time point by reading the file using xr.open_dataset. I printed out outputs of processing this file using some commands in a jyputer notebook in a pdf file, which is also attached. I really have no idea why xr.open_datase cannot read the time coordinate properly. Then, I thought maybe I can redefine its time axis by pd.date_range. But it is also not working. Thank you so much! [Untitled5 - Jupyter Notebook.pdf](https://github.com/pydata/xarray/files/6850435/Untitled5.-.Jupyter.Notebook.pdf) [ts_Amon_CNRM-CM6-1_piControl_r1i1p1f2_gr_185001-234912.tmp.nc.docx](https://github.com/pydata/xarray/files/6850444/ts_Amon_CNRM-CM6-1_piControl_r1i1p1f2_gr_185001-234912.tmp.nc.docx) ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,256496917 https://github.com/pydata/xarray/issues/1565#issuecomment-883589599,https://api.github.com/repos/pydata/xarray/issues/1565,883589599,IC_kwDOAMm_X840qoHf,5635139,2021-07-20T18:04:52Z,2021-07-20T18:04:52Z,MEMBER,"@hding1981 IIUC this isn't supported at the moment. Though with the approaching index refactor, we may be able to support this more easily","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,256496917 https://github.com/pydata/xarray/issues/1565#issuecomment-883585227,https://api.github.com/repos/pydata/xarray/issues/1565,883585227,IC_kwDOAMm_X840qnDL,87719516,2021-07-20T17:57:55Z,2021-07-20T17:57:55Z,NONE,"I have similar problems with time coordinate. How did you solve your problem in the end? I also list my problem here. # The following are my commands in a jupyter notebook import xarray as xr import numpy as np import pandas as pd import sys dset=xr.open_dataset(""input/ts_Amon_CNRM-CM6-1_piControl_r1i1p1f2_gr_185001-234912.nc"",decode_times=False) dset['time'] = pd.period_range(start='1850-01-15', end='2349-12-15', freq='M') varname=""ts"" anom = dset[varname].groupby('time.month')-dset[varname].groupby('time.month').mean('time', keep_attrs=True) # Then, I got the following error message. --------------------------------------------------------------------------- KeyError Traceback (most recent call last) ~/miniconda3/envs/python_tutorial/lib/python3.9/site-packages/xarray/core/dataarray.py in _getitem_coord(self, key) 692 try: --> 693 var = self._coords[key] 694 except KeyError: KeyError: 'time.month' During handling of the above exception, another exception occurred: AttributeError Traceback (most recent call last) in 7 dset['time'] = pd.period_range(start='1850-01-15', end='2349-12-15', freq='M') 8 varname=""ts"" ----> 9 anom = dset[varname].groupby('time.month')-dset[varname].groupby('time.month').mean('time', keep_attrs=True) ~/miniconda3/envs/python_tutorial/lib/python3.9/site-packages/xarray/core/common.py in groupby(self, group, squeeze, restore_coord_dims) 703 ) 704 --> 705 return self._groupby_cls( 706 self, group, squeeze=squeeze, restore_coord_dims=restore_coord_dims 707 ) ~/miniconda3/envs/python_tutorial/lib/python3.9/site-packages/xarray/core/groupby.py in __init__(self, obj, group, squeeze, grouper, bins, restore_coord_dims, cut_kwargs) 313 f""Received {group!r} instead."" 314 ) --> 315 group = obj[group] 316 if len(group) == 0: 317 raise ValueError(f""{group.name} must not be empty"") ~/miniconda3/envs/python_tutorial/lib/python3.9/site-packages/xarray/core/dataarray.py in __getitem__(self, key) 702 def __getitem__(self, key: Any) -> ""DataArray"": 703 if isinstance(key, str): --> 704 return self._getitem_coord(key) 705 else: 706 # xarray-style array indexing ~/miniconda3/envs/python_tutorial/lib/python3.9/site-packages/xarray/core/dataarray.py in _getitem_coord(self, key) 694 except KeyError: 695 dim_sizes = dict(zip(self.dims, self.shape)) --> 696 _, key, var = _get_virtual_variable( 697 self._coords, key, self._level_coords, dim_sizes 698 ) ~/miniconda3/envs/python_tutorial/lib/python3.9/site-packages/xarray/core/dataset.py in _get_virtual_variable(variables, key, level_vars, dim_sizes) 179 data = getattr(ref_var.dt, var_name).data 180 else: --> 181 data = getattr(ref_var, var_name).data 182 virtual_var = Variable(ref_var.dims, data) 183 AttributeError: 'IndexVariable' object has no attribute 'month' ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,256496917 https://github.com/pydata/xarray/issues/1565#issuecomment-521268567,https://api.github.com/repos/pydata/xarray/issues/1565,521268567,MDEyOklzc3VlQ29tbWVudDUyMTI2ODU2Nw==,26384082,2019-08-14T14:26:10Z,2019-08-14T14:26:10Z,NONE,"In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here or remove the `stale` label; otherwise it will be marked as closed automatically ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,256496917 https://github.com/pydata/xarray/issues/1565#issuecomment-329177780,https://api.github.com/repos/pydata/xarray/issues/1565,329177780,MDEyOklzc3VlQ29tbWVudDMyOTE3Nzc4MA==,10050469,2017-09-13T14:03:06Z,2017-09-13T14:03:06Z,MEMBER,"> Potentially we could some sort of API for surfacing this information, e.g., a pandas_dtype property to xarray.Variable. It's probably cleaner, because the dtype of PeriodIndex can be several things, i.e. ``'period[M]'`` in my case.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,256496917 https://github.com/pydata/xarray/issues/1565#issuecomment-328654477,https://api.github.com/repos/pydata/xarray/issues/1565,328654477,MDEyOklzc3VlQ29tbWVudDMyODY1NDQ3Nw==,1217238,2017-09-11T20:50:16Z,2017-09-11T20:50:16Z,MEMBER,"It's only an `dtype=object` array externally: internally, the data is still stored as a `pandas.PeriodIndex`. I think you'll find that inside `ref_var._data.array` . Potentially we could some sort of API for surfacing this information, e.g., a `pandas_dtype` property to `xarray.Variable`.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,256496917 https://github.com/pydata/xarray/issues/1565#issuecomment-328637548,https://api.github.com/repos/pydata/xarray/issues/1565,328637548,MDEyOklzc3VlQ29tbWVudDMyODYzNzU0OA==,10050469,2017-09-11T19:43:19Z,2017-09-11T19:43:19Z,MEMBER,"OK, so the problem is that when given to ``is_datetime_like`` [here](https://github.com/pydata/xarray/blob/5472fb585b9bfda7b0ce5b54d0182d608199df35/xarray/core/dataset.py#L81), the ``pd.PeriodIndex`` is already transformed into an array of dtype ``object``. Before @darothen 's https://github.com/pydata/xarray/pull/1356, the piece if code that was executed is ``date = ref_var.to_index()``, which has the nice property to return a ``PeriodIndex``, as shown here from my debugger: ```python >>> ref_var Out[1]: array([Period('2000-01', 'M'), Period('2000-02', 'M'), Period('2000-03', 'M'), Period('2000-04', 'M'), Period('2000-05', 'M'), Period('2000-06', 'M'), Period('2000-07', 'M'), Period('2000-08', 'M'), Period('2000-09', 'M'), Period('2000-10', 'M'), Period('2000-11', 'M'), Period('2000-12', 'M')], dtype=object) >>> ref_var.to_index() Out[3]: PeriodIndex(['2000-01', '2000-02', '2000-03', '2000-04', '2000-05', '2000-06', '2000-07', '2000-08', '2000-09', '2000-10', '2000-11', '2000-12'], dtype='period[M]', name='time', freq='M') ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,256496917 https://github.com/pydata/xarray/issues/1565#issuecomment-328575741,https://api.github.com/repos/pydata/xarray/issues/1565,328575741,MDEyOklzc3VlQ29tbWVudDMyODU3NTc0MQ==,10050469,2017-09-11T16:00:43Z,2017-09-11T16:00:43Z,MEMBER,Indeed! Will look into it.,"{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,256496917 https://github.com/pydata/xarray/issues/1565#issuecomment-328573731,https://api.github.com/repos/pydata/xarray/issues/1565,328573731,MDEyOklzc3VlQ29tbWVudDMyODU3MzczMQ==,1217238,2017-09-11T15:54:19Z,2017-09-11T15:54:19Z,MEMBER,"Looks like https://github.com/pydata/xarray/pull/1356, which introduced a `is_datatime_like()` check to the dtype of a variable before adding time components.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,256496917 https://github.com/pydata/xarray/issues/1565#issuecomment-328469339,https://api.github.com/repos/pydata/xarray/issues/1565,328469339,MDEyOklzc3VlQ29tbWVudDMyODQ2OTMzOQ==,10050469,2017-09-11T09:13:21Z,2017-09-11T09:13:21Z,MEMBER,"I was wondering which PR was responsible for the regression, but I guess I don't understand the internals well enough to classify this as ""easy fix"" for me ;)","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,256496917 https://github.com/pydata/xarray/issues/1565#issuecomment-328400022,https://api.github.com/repos/pydata/xarray/issues/1565,328400022,MDEyOklzc3VlQ29tbWVudDMyODQwMDAyMg==,1217238,2017-09-11T02:31:41Z,2017-09-11T02:31:41Z,MEMBER,"I never intended to support time attributes on PeriodIndex objects so there was never any test coverage here, but I guess it has been working! Nonetheless this should be pretty easy to fix.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,256496917