home / github

Menu
  • GraphQL API
  • Search all tables

issues

Table actions
  • GraphQL API for issues

2 rows where state = "open", type = "issue" and user = 11671536 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: created_at (date), updated_at (date)

type 1

  • issue · 2 ✖

state 1

  • open · 2 ✖

repo 1

  • xarray 2
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 d-chambers 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 description

I 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 Output

a data array whit a time coordinate of size 3 (ie same shape as da.groupby('time').mean())

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.0.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-138-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 xarray: 0.10.9 pandas: 0.23.4 numpy: 1.15.1 scipy: 1.1.0 netCDF4: 1.4.1 h5netcdf: 0.6.2 h5py: 2.8.0 Nio: None zarr: None cftime: 1.0.1 PseudonetCDF: None rasterio: None iris: None bottleneck: 1.2.1 cyordereddict: None dask: 0.19.1 distributed: 1.23.1 matplotlib: 2.2.3 cartopy: None seaborn: 0.9.0 setuptools: 40.2.0 pip: 18.1 conda: 4.5.11 pytest: 3.8.0 IPython: 6.5.0 sphinx: 1.7.9
{
    "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
}
    xarray 13221727 issue
231715344 MDU6SXNzdWUyMzE3MTUzNDQ= 1428 changes made to coords using groupby and apply do not persist d-chambers 11671536 open 0     1 2017-05-26T19:28:06Z 2020-03-29T15:28:53Z   NONE      

I am running Ubuntu 16 with Xarray 0.9.1 on python 3.6.0.

I have found that any changes made to coordinates in a function that is called by a groupby object's apply method do not persist. The following code illustrates the problem:

```python import numpy as np import xarray as xr

def change_new_coord(dar): """ change the new_coord coord from 1 to 0 """ dar.coords['new_coord'] = 0 return dar

setup data array

data = np.ones((10, 10, 1000)) time = np.linspace(0, 10, 1000) coords = {'time': time, 'd2': range(10), 'd3': range(10)} dims = ['d2', 'd3', 'time'] dar = xr.DataArray(data, coords=coords, dims=dims)

attach coordinate based on d2 and d3

dar.coords['new_coord'] = (('d2', 'd3'), np.ones((10, 10)))

stack

stacked = dar.stack(z=('d2', 'd3'))

groupby

gr = stacked.groupby('z')

apply

out = gr.apply(change_new_coord).unstack('z')

raises; all values in new_coord should be 0, but they are still 1

assert np.all(out.coords['new_coord'] == 0) ```

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/1428/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
    xarray 13221727 issue

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issues] (
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [number] INTEGER,
   [title] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [state] TEXT,
   [locked] INTEGER,
   [assignee] INTEGER REFERENCES [users]([id]),
   [milestone] INTEGER REFERENCES [milestones]([id]),
   [comments] INTEGER,
   [created_at] TEXT,
   [updated_at] TEXT,
   [closed_at] TEXT,
   [author_association] TEXT,
   [active_lock_reason] TEXT,
   [draft] INTEGER,
   [pull_request] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [state_reason] TEXT,
   [repo] INTEGER REFERENCES [repos]([id]),
   [type] TEXT
);
CREATE INDEX [idx_issues_repo]
    ON [issues] ([repo]);
CREATE INDEX [idx_issues_milestone]
    ON [issues] ([milestone]);
CREATE INDEX [idx_issues_assignee]
    ON [issues] ([assignee]);
CREATE INDEX [idx_issues_user]
    ON [issues] ([user]);
Powered by Datasette · Queries took 25.149ms · About: xarray-datasette