issues: 373653203
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
373653203 | MDU6SXNzdWUzNzM2NTMyMDM= | 2508 | groupby fails on generic ndarray functions | 11671536 | open | 0 | 4 | 2018-10-24T20:00:22Z | 2020-10-04T16:05:58Z | NONE | This seems related to #326. Code Sample, a copy-pastable example if possible```python import numpy as np import xarray as xr da = xr.DataArray(np.random.randint(0, 1, (10, 10, 3)), dims=['row', 'col', 'time']) da.groupby('time').apply(np.linalg.norm) ``` Problem descriptionI would expect xarary to know how to apply generic numpy functions along specified axis. However, it currently raises the following exception: ```python AttributeError Traceback (most recent call last) <ipython-input-22-5451ed1f09ee> in <module>() ----> 1 da.groupby('time').apply(np.linalg.norm) ~/anaconda3/lib/python3.7/site-packages/xarray/core/groupby.py in apply(self, func, shortcut, kwargs) 514 applied = (maybe_wrap_array(arr, func(arr, kwargs)) 515 for arr in grouped) --> 516 return self._combine(applied, shortcut=shortcut) 517 518 def _combine(self, applied, shortcut=False): ~/anaconda3/lib/python3.7/site-packages/xarray/core/groupby.py in _combine(self, applied, shortcut) 519 """Recombine the applied objects like the original.""" 520 applied_example, applied = peek_at(applied) --> 521 coord, dim, positions = self._infer_concat_args(applied_example) 522 if shortcut: 523 combined = self._concat_shortcut(applied, dim, positions) ~/anaconda3/lib/python3.7/site-packages/xarray/core/groupby.py in _infer_concat_args(self, applied_example) 289 290 def _infer_concat_args(self, applied_example): --> 291 if self._group_dim in applied_example.dims: 292 coord = self._group 293 positions = self._group_indices AttributeError: 'numpy.float64' object has no attribute 'dims' ``` Expected Outputa data array whit a time coordinate of size 3 (ie same shape as Output of
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/2508/reactions", "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
13221727 | issue |