-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression: time attributes on PeriodIndex #1565
Comments
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. |
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 ;) |
Looks like #1356, which introduced a |
Indeed! Will look into it. |
OK, so the problem is that when given to Before @darothen 's #1356, the piece if code that was executed is >>> ref_var
Out[1]:
<xarray.IndexVariable 'time' (time: 12)>
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') |
It's only an Potentially we could some sort of API for surfacing this information, e.g., a |
It's probably cleaner, because the dtype of PeriodIndex can be several things, i.e. |
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 |
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 notebookimport xarray as xr dset=xr.open_dataset("input/ts_Amon_CNRM-CM6-1_piControl_r1i1p1f2_gr_185001-234912.nc",decode_times=False) Then, I got the following error message.KeyError Traceback (most recent call last) KeyError: 'time.month' During handling of the above exception, another exception occurred: AttributeError Traceback (most recent call last) ~/miniconda3/envs/python_tutorial/lib/python3.9/site-packages/xarray/core/common.py in groupby(self, group, squeeze, restore_coord_dims) ~/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) ~/miniconda3/envs/python_tutorial/lib/python3.9/site-packages/xarray/core/dataarray.py in getitem(self, key) ~/miniconda3/envs/python_tutorial/lib/python3.9/site-packages/xarray/core/dataarray.py in _getitem_coord(self, key) ~/miniconda3/envs/python_tutorial/lib/python3.9/site-packages/xarray/core/dataset.py in _get_virtual_variable(variables, key, level_vars, dim_sizes) AttributeError: 'IndexVariable' object has no attribute 'month' |
@hding1981 IIUC this isn't supported at the moment. Though with the approaching index refactor, we may be able to support this more easily |
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 |
@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. |
The following used to work with xarray 0.9.5 but doesn't anymore with 0.9.6 or master:
The text was updated successfully, but these errors were encountered: