-
-
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
full_like, ones_like, zeros_like should retain subclasses #2542
Comments
Are there other functions where we don't do this? I would be happy to accept a fix here. I don't think we need a few keyword argument -- I expect most subclass users would consider this a bug rather than a feature. We might consider adding an official subclassing APIs like pandas: |
Implement a workaround for pydata/xarray#2542 where subclasses are lost by zeros_like.
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 |
Shall we fold this into #3980? (i.e. I don't think we need an issue for enabling subclassing for each method :) ) |
Code Sample,
Problem description
I would expect that
type(da2) is type(da)
, but this is not the case. The type ofda
is always<class 'xarray.core.dataarray.DataArray'>
. Rather, the output of this script is:<class '__main__.MyDataArray'> <class 'xarray.core.dataarray.DataArray'>
Expected Output
I would hope as an output:
<class '__main__.MyDataArray'> <class '__main__.MyDataArray'>
In principle changing this could break people's code, so if a change is implemented it should probably be through an optional keyword argument to the
full_like
/ones_like
/zeros_like
family.Output of
xr.show_versions()
xarray: 0.10.7
pandas: 0.23.2
numpy: 1.15.2
scipy: 1.1.0
netCDF4: 1.4.0
h5netcdf: 0.6.1
h5py: 2.8.0
Nio: None
zarr: None
bottleneck: 1.2.1
cyordereddict: None
dask: 0.18.1
distributed: 1.22.0
matplotlib: 3.0.0
cartopy: 0.16.0
seaborn: 0.9.0
setuptools: 39.2.0
pip: 18.0
conda: None
pytest: 3.2.2
IPython: 6.4.0
sphinx: None
The text was updated successfully, but these errors were encountered: