home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 231715344

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
231715344 MDU6SXNzdWUyMzE3MTUzNDQ= 1428 changes made to coords using groupby and apply do not persist 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
}
    13221727 issue

Links from other tables

  • 1 row from issues_id in issues_labels
  • 1 row from issue in issue_comments
Powered by Datasette · Queries took 0.657ms · About: xarray-datasette