home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 604553156

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/1519#issuecomment-604553156 https://api.github.com/repos/pydata/xarray/issues/1519 604553156 MDEyOklzc3VlQ29tbWVudDYwNDU1MzE1Ng== 14808389 2020-03-26T17:07:42Z 2020-03-26T17:50:49Z MEMBER

it's not that it fails, the original dataset is just not updated: ```python In [2]: ds = xr.Dataset({ ...: "a": ("x", np.arange(4)), ...: "b": ("x", np.arange(4)), ...: })

In [3]: selected = ds.loc[{"x": 1}] ...: selected["a"] = 10 ...: ds, selected Out[3]: (<xarray.Dataset> Dimensions: (x: 4) Dimensions without coordinates: x Data variables: a (x) int64 0 1 2 3 b (x) int64 0 1 2 3, <xarray.Dataset> Dimensions: () Data variables: a int64 10 b int64 1) to make it work, use (note the `[...]`)python In [7]: selected = ds.loc[{"x": 1}] ...: selected["a"][...] = 10 ...: ds, selected Out[7]: (<xarray.Dataset> Dimensions: (x: 4) Dimensions without coordinates: x Data variables: a (x) int64 0 10 2 3 b (x) int64 0 1 2 3, <xarray.Dataset> Dimensions: () Data variables: a int64 10 b int64 1) `` The difference is that without the extra[...]we don't modify the values but instead create a new variable (so something likeds["new_variable"] = ("x", [1, 3, 4, 5])`)

Also note that while ds.a.sel(x=1) = 10 raises a SyntaxError, ds.a.sel(x=1)[...] = 10 or ds.sel(x=1).a[...] = 10 have exactly the same effect as their loc counterparts.

We probably should add an explanation and examples to the documentation (loc / sel and maybe the indexing page?)

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  252490115
Powered by Datasette · Queries took 0.742ms · About: xarray-datasette