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

Groupby.mean() AttributeError: 'ScipyArrayWrapper' object has no attribute 'oindex' #9272

Closed
2 of 5 tasks
hunterboerner opened this issue Jul 24, 2024 · 2 comments
Closed
2 of 5 tasks
Labels
bug needs triage Issue that has not been reviewed by xarray team member

Comments

@hunterboerner
Copy link

What happened?

min_days = loca_tasmin.groupby("time.dayofyear")
min_days.mean()

gives

AttributeError: 'ScipyArrayWrapper' object has no attribute 'oindex'

What did you expect to happen?

It should compute the means

Minimal Complete Verifiable Example

No response

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 2
      1 min_days = loca_tasmin.groupby("time.dayofyear")
----> 2 min_days.mean()

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/_aggregations.py:5929, in DataArrayGroupByAggregations.mean(self, dim, skipna, keep_attrs, **kwargs)
   5920     return self._flox_reduce(
   5921         func="mean",
   5922         dim=dim,
   (...)
   5926         **kwargs,
   5927     )
   5928 else:
-> 5929     return self._reduce_without_squeeze_warn(
   5930         duck_array_ops.mean,
   5931         dim=dim,
   5932         skipna=skipna,
   5933         keep_attrs=keep_attrs,
   5934         **kwargs,
   5935     )

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/groupby.py:1761, in DataArrayGroupByBase._reduce_without_squeeze_warn(self, func, dim, axis, keep_attrs, keepdims, shortcut, **kwargs)
   1758     warnings.filterwarnings("ignore", message="The `squeeze` kwarg")
   1759     check_reduce_dims(dim, self.dims)
-> 1761 return self._map_maybe_warn(reduce_array, shortcut=shortcut, warn_squeeze=False)

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/groupby.py:1601, in DataArrayGroupByBase._map_maybe_warn(self, func, args, warn_squeeze, shortcut, **kwargs)
   1595 grouped = (
   1596     self._iter_grouped_shortcut(warn_squeeze)
   1597     if shortcut
   1598     else self._iter_grouped(warn_squeeze)
   1599 )
   1600 applied = (maybe_wrap_array(arr, func(arr, *args, **kwargs)) for arr in grouped)
-> 1601 return self._combine(applied, shortcut=shortcut)

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/groupby.py:1620, in DataArrayGroupByBase._combine(self, applied, shortcut)
   1618 def _combine(self, applied, shortcut=False):
   1619     """Recombine the applied objects like the original."""
-> 1620     applied_example, applied = peek_at(applied)
   1621     coord, dim, positions = self._infer_concat_args(applied_example)
   1622     if shortcut:

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/utils.py:205, in peek_at(iterable)
    201 """Returns the first value from iterable, as well as a new iterator with
    202 the same content as the original iterable
    203 """
    204 gen = iter(iterable)
--> 205 peek = next(gen)
    206 return peek, itertools.chain([peek], gen)

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/groupby.py:1600, in <genexpr>(.0)
   1586 def _map_maybe_warn(
   1587     self,
   1588     func: Callable[..., DataArray],
   (...)
   1593     **kwargs: Any,
   1594 ) -> DataArray:
   1595     grouped = (
   1596         self._iter_grouped_shortcut(warn_squeeze)
   1597         if shortcut
   1598         else self._iter_grouped(warn_squeeze)
   1599     )
-> 1600     applied = (maybe_wrap_array(arr, func(arr, *args, **kwargs)) for arr in grouped)
   1601     return self._combine(applied, shortcut=shortcut)

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/groupby.py:1748, in DataArrayGroupByBase._reduce_without_squeeze_warn.<locals>.reduce_array(ar)
   1747 def reduce_array(ar: DataArray) -> DataArray:
-> 1748     return ar.reduce(
   1749         func=func,
   1750         dim=dim,
   1751         axis=axis,
   1752         keep_attrs=keep_attrs,
   1753         keepdims=keepdims,
   1754         **kwargs,
   1755     )

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/variable.py:1662, in Variable.reduce(self, func, dim, axis, keep_attrs, keepdims, **kwargs)
   1655 keep_attrs_ = (
   1656     _get_keep_attrs(default=False) if keep_attrs is None else keep_attrs
   1657 )
   1659 # Noe that the call order for Variable.mean is
   1660 #    Variable.mean -> NamedArray.mean -> Variable.reduce
   1661 #    -> NamedArray.reduce
-> 1662 result = super().reduce(
   1663     func=func, dim=dim, axis=axis, keepdims=keepdims, **kwargs
   1664 )
   1666 # return Variable always to support IndexVariable
   1667 return Variable(
   1668     result.dims, result._data, attrs=result._attrs if keep_attrs_ else None
   1669 )

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/namedarray/core.py:905, in NamedArray.reduce(self, func, dim, axis, keepdims, **kwargs)
    901     if isinstance(axis, tuple) and len(axis) == 1:
    902         # unpack axis for the benefit of functions
    903         # like np.argmin which can't handle tuple arguments
    904         axis = axis[0]
--> 905     data = func(self.data, axis=axis, **kwargs)
    906 else:
    907     data = func(self.data, **kwargs)

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/variable.py:448, in Variable.data(self)
    446     return self._data
    447 elif isinstance(self._data, indexing.ExplicitlyIndexed):
--> 448     return self._data.get_duck_array()
    449 else:
    450     return self.values

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/indexing.py:836, in MemoryCachedArray.get_duck_array(self)
    835 def get_duck_array(self):
--> 836     self._ensure_cached()
    837     return self.array.get_duck_array()

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/indexing.py:830, in MemoryCachedArray._ensure_cached(self)
    829 def _ensure_cached(self):
--> 830     self.array = as_indexable(self.array.get_duck_array())

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/indexing.py:787, in CopyOnWriteArray.get_duck_array(self)
    786 def get_duck_array(self):
--> 787     return self.array.get_duck_array()

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/indexing.py:646, in LazilyIndexedArray.get_duck_array(self)
    644 def get_duck_array(self):
    645     if isinstance(self.array, ExplicitlyIndexedNDArrayMixin):
--> 646         array = apply_indexer(self.array, self.key)
    647     else:
    648         # If the array is not an ExplicitlyIndexedNDArrayMixin,
    649         # it may wrap a BackendArray so use its __getitem__
    650         array = self.array[self.key]

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/indexing.py:1027, in apply_indexer(indexable, indexer)
   1025     return indexable.vindex[indexer]
   1026 elif isinstance(indexer, OuterIndexer):
-> 1027     return indexable.oindex[indexer]
   1028 else:
   1029     return indexable[indexer]

File ~/.asdf/installs/python/3.11.0/lib/python3.11/site-packages/xarray/core/indexing.py:367, in IndexCallable.__getitem__(self, key)
    366 def __getitem__(self, key: Any) -> Any:
--> 367     return self.getter(key)

File ~/.asdf/installs/python/3.11.0/lib/python3.11/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)

AttributeError: 'ScipyArrayWrapper' object has no attribute 'oindex'

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.11.0 (main, Jun 19 2024, 18:41:10) [Clang 15.0.0 (clang-1500.1.0.2.5)] python-bits: 64 OS: Darwin OS-release: 23.3.0 machine: arm64 processor: arm byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.2 libnetcdf: None

xarray: 2024.6.0
pandas: 2.2.2
numpy: 1.24.4
scipy: 1.14.0
netCDF4: None
pydap: None
h5netcdf: 1.3.0
h5py: 3.11.0
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.9.1
cartopy: 0.23.0
seaborn: None
numbagg: 0.8.1
fsspec: 2024.6.0
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 65.5.0
pip: 22.3
conda: None
pytest: None
mypy: None
IPython: 8.26.0
sphinx: None

@hunterboerner hunterboerner added bug needs triage Issue that has not been reviewed by xarray team member labels Jul 24, 2024
Copy link

welcome bot commented Jul 24, 2024

Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!

@dcherian
Copy link
Contributor

Dupe of #8909

@dcherian dcherian closed this as not planned Won't fix, can't repro, duplicate, stale Jul 24, 2024
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