-
-
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
RecursionError when defining __slots__ on subclass using Containment #4660
Comments
inheriting from a The reason your examples fail with a class MyClass:
__slots__ = ("dataset",)
def __init__(self, ds):
self.__class__.dataset.__set__(self, ds)
def __getattr__(self, k):
return getattr(self.dataset, k)
def __setattr__(self, k, v):
setattr(self.dataset, k, v)
ds = xr.Dataset()
x = MyClass(ds) but I've also seen the use of Be aware that the result of def __getattr__(self, k):
result = getattr(self.dataset, k)
if isinstance(result, (xr.Dataset, xr.DataArray)):
return type(self)(result)
else:
return result |
I assume this answered your question. If you disagree, feel free to reopen. |
Though we don't support it officially, I've found subclassing a |
Sorry for my long time to reply, christmas... For the moment, I will try to implement Extending xarray as you pointed using "xr.register_dataset_accessor". Create a new class that cannot be identified as 'isinstance(object, xarray.Dataset)' might be an issue in my case. |
What happened:
Inheritance of xarray.Dataset request the addition of
__slots__
:however when added, produces RecursionError.
What you expected to happen:
It should be possible to use Containment & Delegation on xarray classes.
Minimal Complete Verifiable Example:
Returns:
Anything else we need to know?:
I would recommend to add the following test or similar to ensure it is working:
Environment:
Output of xr.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.12 |Anaconda, Inc.| (default, Sep 8 2020, 23:10:56)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 5.4.0-56-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.6.3
xarray: 0.16.2
pandas: 1.1.4
numpy: 1.19.4
scipy: 1.5.4
netCDF4: 1.5.4
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.3.0
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2.30.0
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
pint: None
setuptools: 51.0.0.post20201207
pip: 20.3.1
conda: None
pytest: 6.1.2
IPython: None
sphinx: 3.2.1
The text was updated successfully, but these errors were encountered: