Open
Description
What happened?
Exception ScipyArrayWrapper' object has no attribute 'oindex'
when trying to save dataset into netcdf file after selecting subset from dataset previously loaded from another netcdf file.
What did you expect to happen?
No response
Minimal Complete Verifiable Example
import xarray as xr
ds = xr.Dataset()
ds['A'] = xr.DataArray([[1, 'a'], [2,'b']],dims=['x','y'])
ds.to_netcdf('test.nc')
ds2 = xr.open_dataset('test.nc')
ds2.sel(y=[1]).to_netcdf('test.nc')
MVCE confirmation
- Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- Complete example — the example is self-contained, including all data and the text of any traceback.
- Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- New issue — a search of GitHub Issues suggests this is not a duplicate.
- Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
File ~/Workspace/phd/.venv/lib/python3.10/site-packages/xarray/core/indexing.py:342, in IndexCallable.__getitem__(self, key)
341 def __getitem__(self, key: Any) -> Any:
--> 342 return self.getter(key)
File ~/Workspace/phd/.venv/lib/python3.10/site-packages/xarray/coding/variables.py:72, in _ElementwiseFunctionArray._oindex_get(self, key)
71 def _oindex_get(self, key):
---> 72 return type(self)(self.array.oindex[key], self.func, self.dtype)
File ~/Workspace/phd/.venv/lib/python3.10/site-packages/xarray/core/indexing.py:342, in IndexCallable.__getitem__(self, key)
341 def __getitem__(self, key: Any) -> Any:
--> 342 return self.getter(key)
File ~/Workspace/phd/.venv/lib/python3.10/site-packages/xarray/coding/strings.py:256, in StackedBytesArray._oindex_get(self, key)
255 def _oindex_get(self, key):
--> 256 return _numpy_char_to_bytes(self.array.oindex[key])
AttributeError: 'ScipyArrayWrapper' object has no attribute 'oindex'
Anything else we need to know?
No response
Environment
INSTALLED VERSIONS
------------------
commit: None
python: 3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:26:04) [GCC 10.4.0]
python-bits: 64
OS: Linux
OS-release: 6.5.0-26-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.14.2
libnetcdf: None
xarray: 2024.3.0
pandas: 2.2.1
numpy: 1.26.4
scipy: 1.13.0
netCDF4: None
pydap: None
h5netcdf: None
h5py: 3.10.0
Nio: None
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: 1.3.8
dask: 2024.4.0
distributed: 2024.4.0
matplotlib: 3.8.4
cartopy: None
seaborn: 0.13.2
numbagg: None
fsspec: 2024.3.1
cupy: None
pint: None
sparse: None
flox: 0.9.6
numpy_groupies: 0.10.2
setuptools: 63.2.0
pip: 24.0
conda: None
pytest: 8.1.1
mypy: None
IPython: 8.23.0
sphinx: None