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

Unloaded DataArray opened with scipy missing attributes when sliced with a sequence #9300

Closed
5 tasks done
aulemahal opened this issue Jul 31, 2024 · 3 comments
Closed
5 tasks done
Labels
bug needs triage Issue that has not been reviewed by xarray team member

Comments

@aulemahal
Copy link
Contributor

aulemahal commented Jul 31, 2024

What happened?

I opened the "air_temperature" dataset using the scipy engine, sliced on a dimension with a list of index and received a seemingly "incomplete" object. It raises AttributeError: 'DataArray' object has no attribute 'data' and similar with values.

What did you expect to happen?

I expected the sliced result to be a normal DataArray.

Minimal Complete Verifiable Example

import xarray  as xr

ds = xr.tutorial.open_dataset("air_temperature", engine='scipy')

ds.air.isel(lat=20).data  # Works

ds.air.isel(lat=slice(20, 22)).data  # Works

ds.air.isel(lat=[20, 21]).data # Fails

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

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[10], line 1
----> 1 ds.air.isel(lat=[20, 21]).data

File ~/miniforge3/envs/xclim/lib/python3.12/site-packages/xarray/core/common.py:286, in AttrAccessMixin.__getattr__(self, name)
    284         with suppress(KeyError):
    285             return source[name]
--> 286 raise AttributeError(
    287     f"{type(self).__name__!r} object has no attribute {name!r}"
    288 )

AttributeError: 'DataArray' object has no attribute 'data'

Anything else we need to know?

If I ds.air.load() first, this doesn't happen.

Environment

INSTALLED VERSIONS

commit: None
python: 3.12.4 | packaged by conda-forge | (main, Jun 17 2024, 10:23:07) [GCC 12.3.0]
python-bits: 64
OS: Linux
OS-release: 6.9.6-200.fc40.x86_64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: fr_CA.UTF-8
LOCALE: ('fr_CA', 'UTF-8')
libhdf5: 1.14.3
libnetcdf: None

xarray: 2024.7.0
pandas: 2.2.2
numpy: 2.0.1
scipy: 1.14.0
netCDF4: None
pydap: None
h5netcdf: 1.3.0
h5py: 3.11.0
zarr: None
cftime: 1.6.4
nc_time_axis: 1.4.1
iris: None
bottleneck: 1.4.0
dask: 2024.7.1
distributed: 2024.7.1
matplotlib: 3.9.1
cartopy: None
seaborn: None
numbagg: None
fsspec: 2024.6.1
cupy: None
pint: 0.24.3
sparse: 0.16.0a10.dev3+ga73b20d
flox: 0.9.8
numpy_groupies: 0.11.1
setuptools: 71.0.4
pip: 24.1.2
conda: None
pytest: 7.4.4
mypy: 1.11.0
IPython: 8.26.0
sphinx: 7.4.7

@aulemahal aulemahal added bug needs triage Issue that has not been reviewed by xarray team member labels Jul 31, 2024
@dcherian
Copy link
Contributor

Works for me.

'DataArray' object has no attribute 'da

looks like a typo?

@aulemahal aulemahal changed the title Unloaded DataArray missing attributes when sliced with a sequence Unloaded DataArray opened with scipy missing attributes when sliced with a sequence Jul 31, 2024
@aulemahal
Copy link
Contributor Author

aulemahal commented Jul 31, 2024

It was indeed a typo, now fixed.

Turns out this does not happen when the dataset is opened with netCDF4, but it does with scipy. I updated the issue.

Sorry I thus misattributed this to xarray 2024.07, but the error also happens with 2024.06.0.

For context, we had too many issues with netCDF4's recent updates on one of our CI and it was much easier to simply remove it. Almost all other datasets we use are NETCDF4/HDF5, except the few calls in some notebooks to "air_temperature", which is NETCDF3 and opens with scipy.

@dcherian
Copy link
Contributor

dcherian commented Jul 31, 2024

OK This is a dupe of #8909 which snuck in because it only manifests when using engine="scipy" and netCDF is not installed.

The raised message is misleading and hides the real cause. I'll get to it soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs triage Issue that has not been reviewed by xarray team member
Projects
None yet
Development

No branches or pull requests

2 participants