Skip to content
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

Can't create weakrefs on DataArrays since xarray 0.13.0 #3317

Closed
mraspaud opened this issue Sep 18, 2019 · 8 comments · Fixed by #3318
Closed

Can't create weakrefs on DataArrays since xarray 0.13.0 #3317

mraspaud opened this issue Sep 18, 2019 · 8 comments · Fixed by #3318
Assignees

Comments

@mraspaud
Copy link
Contributor

MCVE Code Sample

import xarray as xr
from weakref import ref
arr = xr.DataArray([1, 2, 3])
ref(arr)

Expected Output

I expect the weak reference to be created as in former versions

Problem Description

The above code raises the following exception:
TypeError: cannot create weak reference to 'DataArray' object

Output of xr.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 3.10.0-1062.1.1.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8
libhdf5: 1.10.4
libnetcdf: 4.6.2

xarray: 0.13.0
pandas: 0.25.1
numpy: 1.17.0
scipy: 1.3.0
netCDF4: 1.5.1.2
pydap: None
h5netcdf: 0.7.4
h5py: 2.9.0
Nio: None
zarr: None
cftime: 1.0.3.4
nc_time_axis: None
PseudoNetCDF: None
rasterio: 1.0.22
cfgrib: None
iris: None
bottleneck: None
dask: 2.3.0
distributed: 2.4.0
matplotlib: 3.1.1
cartopy: 0.17.0
seaborn: None
numbagg: None
setuptools: 41.2.0
pip: 19.2.3
conda: None
pytest: 5.0.1
IPython: 7.8.0
sphinx: None

@crusaderky
Copy link
Contributor

I'm on it

@crusaderky crusaderky self-assigned this Sep 18, 2019
@keewis
Copy link
Collaborator

keewis commented Sep 18, 2019

From the docs on __slots__, it seems that for weakref to work, it needs a __weakref__ attribute.

@crusaderky
Copy link
Contributor

Indeed this was introduced by #3250. Working on a fix.

@crusaderky
Copy link
Contributor

@mraspaud is it ok to allow weakrefs for DataArray and Dataset objects only? Adding support for more objects will harm RAM consumption for all.

@crusaderky
Copy link
Contributor

@mraspaud temporary workaround:

class DataArrayWithWeakRef(xarray.DataArray):
    __slots__ = ("__weakref__", )

a = DataArrayWithWeakRef([1, 2, 3])
ref(a)

<weakref at 0x11e3b1e58; to 'DataArrayWithWeakRef' at 0x11ef3cd68>

@crusaderky crusaderky mentioned this issue Sep 18, 2019
4 tasks
@mraspaud
Copy link
Contributor Author

mraspaud commented Sep 18, 2019

@crusaderky yep, supporting DataArray and Dataset objects is what we need.

@mraspaud
Copy link
Contributor Author

and thanks for the workaround and impressively fast reaction :)

Chilipp pushed a commit to Chilipp/psy-strat that referenced this issue Sep 18, 2019
@crusaderky
Copy link
Contributor

xarray 0.14.0 is out on conda-forge now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants