Skip to content
This repository was archived by the owner on Apr 30, 2021. It is now read-only.
This repository was archived by the owner on Apr 30, 2021. It is now read-only.

esmlab.resample() error with xarray 0.15.1 #165

@mnlevy1981

Description

@mnlevy1981

Description

I have a notebook that relies on esmlab.resample() that dies with ValueError: Cannot assign to the .data attribute of dimension coordinate a.k.a IndexVariable 'time'.

What I Did

Cell [6] from this notebook:

%%time

datasets_ann = dict()
for exp in datasets:
    datasets_ann[exp] = esmlab.resample(datasets[exp], freq='ann')
    print(f'\n{exp}\n----\n{datasets_ann[exp]}')

resulted in

Details
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<timed exec> in <module>

/glade/work/mlevy/miniconda3/envs/cesm2-marbl-new/lib/python3.7/site-packages/esmlab/core.py in resample(dset, freq, weights, time_coord_name, method)
    780 
    781     else:
--> 782         ds = dset.esmlab.set_time(time_coord_name=time_coord_name).compute_ann_mean(
    783             weights=weights, method=method
    784         )

/glade/work/mlevy/miniconda3/envs/cesm2-marbl-new/lib/python3.7/site-packages/esmlab/core.py in set_time(self, time_coord_name, year_offset)
    358                     print('Please open dataset with `decode_times=False`')
    359                     raise exc
--> 360         self.setup()
    361         return self
    362 

/glade/work/mlevy/miniconda3/envs/cesm2-marbl-new/lib/python3.7/site-packages/esmlab/core.py in setup(self)
    363     def setup(self):
    364         self.get_variables()
--> 365         self.compute_time()
    366         self.get_original_metadata()
    367 

/glade/work/mlevy/miniconda3/envs/cesm2-marbl-new/lib/python3.7/site-packages/esmlab/core.py in compute_time(self)
     80 
     81         if self.time_bound is not None:
---> 82             groupby_coord = self.get_time_decoded(midpoint=True)
     83 
     84         else:

/glade/work/mlevy/miniconda3/envs/cesm2-marbl-new/lib/python3.7/site-packages/esmlab/core.py in get_time_decoded(self, midpoint)
    185                 units=self.time_attrs['units'],
    186                 calendar=self.time_attrs['calendar'],
--> 187                 only_use_cftime_datetimes=True,
    188             )
    189         )

/glade/work/mlevy/miniconda3/envs/cesm2-marbl-new/lib/python3.7/site-packages/xarray/core/common.py in __setattr__(self, name, value)
    260         """
    261         try:
--> 262             object.__setattr__(self, name, value)
    263         except AttributeError as e:
    264             # Don't accidentally shadow custom AttributeErrors, e.g.

/glade/work/mlevy/miniconda3/envs/cesm2-marbl-new/lib/python3.7/site-packages/xarray/core/dataarray.py in data(self, value)
    551     @data.setter
    552     def data(self, value: Any) -> None:
--> 553         self.variable.data = value
    554 
    555     @property

/glade/work/mlevy/miniconda3/envs/cesm2-marbl-new/lib/python3.7/site-packages/xarray/core/variable.py in data(self, data)
   2106     def data(self, data):
   2107         raise ValueError(
-> 2108             f"Cannot assign to the .data attribute of dimension coordinate a.k.a IndexVariable {self.name!r}. "
   2109             f"Please use DataArray.assign_coords, Dataset.assign_coords or Dataset.assign as appropriate."
   2110         )

ValueError: Cannot assign to the .data attribute of dimension coordinate a.k.a IndexVariable 'time'. Please use DataArray.assign_coords, Dataset.assign_coords or Dataset.assign as appropriate.

Output of esmlab.show_versions()

Details
>>> esmlab.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.7.6 | packaged by conda-forge | (default, Mar 23 2020, 23:03:20)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 3.10.0-693.21.1.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

esmlab: 2019.4.27.post55
xarray: 0.15.1
pandas: 1.0.3
numpy: 1.18.1
scipy: 1.4.1
xesmf: installed
cftime: 1.0.3.4
dask: 2.13.0
distributed: 2.13.0
setuptools: 46.1.3.post20200325
pip: 20.0.2
conda: None
pytest: 5.4.1
IPython: 7.13.0
sphinx: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions