-
-
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
Assigning with .loc indexing: implicit effect of dimension order? #7030
Comments
We are experiencing the same issue (with xarray version 2022.3.0). After a bit of exploring it seems that in the |
Thanks @maarten-vandenberg . It looks like you have made an important step toward solving the problem. Do you have time to open a pull request fixing this issue? Even an incomplete one helps get us closer to a fix. |
I'd be happy to open a pull request, although I must admit I'm not very familiar with the internals of xarray. I hope it will help to clarify the issue and bring a potential solution closer |
I also ran into this. Here's a workaround that seems to work in some cases, which uses a Dataset and explicit broadcasting: index = xarray.Dataset({'a': 0})
index, value = xarray.broadcast(index, bc)
acb.loc[index] = value
assert (abc == acb).all() This doesn't work in all cases, such as when value = bc.broadcast_like(acb[dict(a=0)])
acb[dict(a=0)] = value
assert (abc == acb).all() |
I attempted to solve this in #8067. Until/unless that gets accepted, I think an acceptable workaround could be acb.loc[dict(a=0)] = bc.variable |
* Add unit test for Variable[...] = DataArray (#7030) * Check for DataArray instance (#7030) * Update whats-new.rst (#7030) * Revert Variable and fix DataArray instead (#7030) * Add test case for .loc[...] = dataarray (#7030) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix whats-new.rst (#7030) * Add regression test for Dataset (#7030) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maximilian Roos <[email protected]>
What happened?
Assigning a DataArray to a subset of another DataArray seems to depend on the order of the dimensions
What did you expect to happen?
I would expect xarray to automatically align the dimensions appropriately.
Minimal Complete Verifiable Example
Example 1:
Example 2:
Same as example 1, but instead of raising a ValueError, runs without error, but gives incorrect results because it ignores dimension order
MVCE confirmation
Relevant log output
No response
Anything else we need to know?
No response
Environment
xarray: 2022.6.0
pandas: 1.4.3
numpy: 1.23.1
scipy: 1.9.0
netCDF4: 1.6.0
pydap: None
h5netcdf: None
h5py: 3.7.0
Nio: None
zarr: None
cftime: 1.6.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.5.2
cartopy: None
seaborn: None
numbagg: None
fsspec: 2022.7.1
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 63.4.2
pip: 22.2.2
conda: 4.14.0
pytest: 7.1.2
IPython: 8.4.0
sphinx: None
The text was updated successfully, but these errors were encountered: