-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assignment #1519
Comments
I'm re-pinging this issue since I was just bitten by it (on version 0.15). If creating an exception is time consuming could we instead have a disclaimer regarding this behavior to the documentation? Here's a basic working example that shows that it does silently fail:
|
it's not that it fails, the original dataset is just not updated: 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 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 Also note that while We probably should add an explanation and examples to the documentation ( |
also, we can't really raise only for intermediate_ds = ds.loc[...]
intermediate_ds[name] = -1 where the second line is something we explicitly want to support. |
since it came up in #3939, I played around with this, and it seems the |
How does this even work? 😱 |
In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity If this issue remains relevant, please comment here or remove the |
Assignment of individual elements / subsets seems to be only partially supported, but I have not found clear documentation on it. After playing a bit around with xarray I believe the current support boils down to the following (I list some issues I see with the current documentation and how things seem to work).
DataSet
ds.loc[selector_dict].NAME_OF_VARIABLE = -1
Doesn't work but at least throws an error (Use __setitem__ style assignment (e.g., ds['name'] = ...) instead to assign variables.
)ds.loc[selector_dict]["NAME_OF_VARIABLE"] = -1
Silently failsNAME_OF_VARIABLE
may only be known at runtime. Indexing with alignment and broadcasting #974 May fix this (?).ds.sel
DataArray
(Can be obtained via ds['name'])
.sel
(which is documented to return a new DataArray, so arguably it's expected not to work)ds["NAME_OF_VARIABLE"].sel(**selector_dict) = -1
Invalid python syntaxds["NAME_OF_VARIABLE"].sel(**selector_dict).values = -1
Silently fails.loc
ds["NAME_OF_VARIABLE"].loc[selector_dict] = -1
worksIs this the recommended behaviour? Then I believe the wrong pattern of
ds.loc[selector_dict]["NAME_OF_VARIABLE"] = -1
should be documented andds[NAME_OF_VARIABLE].loc[selector_dict] = -1
instead suggested.The text was updated successfully, but these errors were encountered: