issues: 2073024461
This data as json
id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2073024461 | I_kwDOAMm_X857j9fN | 8602 | `DataArray.mean()` and `Dataset.mean()` fail with `sparse==0.15.0` | 46072231 | closed | 0 | 4 | 2024-01-09T19:27:47Z | 2024-01-10T14:44:57Z | 2024-01-10T14:44:57Z | NONE | What happened?The following script leads to an error: ``` import numpy as np import xarray as xr from sparse import GCXS x = np.random.negative_binomial(1, 0.5, size=(100, 100)) array = xr.DataArray(GCXS.from_numpy(x)) array.mean() ``` ```AttributeError Traceback (most recent call last) Cell In[16], line 1 ----> 1 array.mean() File ~/.../python3.11/site-packages/xarray/core/_aggregations.py:1663, in DataArrayAggregations.mean(self, dim, skipna, keep_attrs, kwargs)
1588 def mean(
1589 self,
1590 dim: Dims = None,
(...)
1594 kwargs: Any,
1595 ) -> Self:
1596 """
1597 Reduce this DataArray's data by applying File ~/.../python3.11/site-packages/xarray/core/dataarray.py:3776, in DataArray.reduce(self, func, dim, axis, keep_attrs, keepdims, kwargs)
3732 def reduce(
3733 self,
3734 func: Callable[..., Any],
(...)
3740 kwargs: Any,
3741 ) -> Self:
3742 """Reduce this array by applying File ~/.../python3.11/site-packages/xarray/core/variable.py:1756, in Variable.reduce(self, func, dim, axis, keep_attrs, keepdims, kwargs) 1749 keep_attrs_ = ( 1750 _get_keep_attrs(default=False) if keep_attrs is None else keep_attrs 1751 ) 1753 # Noe that the call order for Variable.mean is 1754 # Variable.mean -> NamedArray.mean -> Variable.reduce 1755 # -> NamedArray.reduce -> 1756 result = super().reduce( 1757 func=func, dim=dim, axis=axis, keepdims=keepdims, kwargs 1758 ) 1760 # return Variable always to support IndexVariable 1761 return Variable( 1762 result.dims, result.data, attrs=result._attrs if keep_attrs else None 1763 ) File ~/.../python3.11/site-packages/xarray/namedarray/core.py:772, in NamedArray.reduce(self, func, dim, axis, keepdims, kwargs) 770 data = func(self.data, axis=axis, kwargs) 771 else: --> 772 data = func(self.data, **kwargs) 774 if getattr(data, "shape", ()) == self.shape: 775 dims = self.dims File ~/.../python3.11/site-packages/xarray/core/duck_array_ops.py:637, in mean(array, axis, skipna, kwargs) 635 return _to_pytimedelta(mean_timedeltas, unit="us") + offset 636 else: --> 637 return _mean(array, axis=axis, skipna=skipna, kwargs) File ~/.../python3.11/site-packages/xarray/core/duck_array_ops.py:399, in _create_nan_agg_method.<locals>.f(values, axis, skipna, **kwargs) 396 kwargs.pop("min_count", None) 398 xp = get_array_namespace(values) --> 399 func = getattr(xp, name) 401 try: 402 with warnings.catch_warnings(): AttributeError: module 'sparse' has no attribute 'mean' ``` What did you expect to happen?Reproducible script runs without error with Minimal Complete Verifiable ExampleNo response MVCE confirmation
Relevant log outputNo response Anything else we need to know?No response Environment
INSTALLED VERSIONS
------------------
commit: None
python: 3.11.6 | packaged by conda-forge | (main, Oct 3 2023, 10:40:35) [GCC 12.3.0]
python-bits: 64
OS: Linux
OS-release: 6.2.0-34-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: 2023.12.0
pandas: 1.5.3
numpy: 1.24.4
scipy: 1.11.4
netCDF4: None
pydap: None
h5netcdf: None
h5py: 3.10.0
Nio: None
zarr: None
cftime: None
nc_time_axis: None
iris: None
bottleneck: None
dask: 2023.12.0
distributed: 2023.12.0
matplotlib: 3.8.2
cartopy: None
seaborn: 0.12.2
numbagg: None
fsspec: 2023.12.0
cupy: None
pint: None
sparse: 0.15.0
flox: None
numpy_groupies: 0.10.2
setuptools: 68.2.2
pip: 23.3.1
conda: None
pytest: 7.4.3
mypy: None
IPython: 8.18.1
sphinx: None
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/8602/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |