issues: 1371769156
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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1371769156 | I_kwDOAMm_X85Rw4lE | 7030 | Assigning with .loc indexing: implicit effect of dimension order? | 6875882 | closed | 0 | 5 | 2022-09-13T17:19:07Z | 2023-09-12T18:17:11Z | 2023-09-12T18:17:11Z | CONTRIBUTOR | 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 ExampleExample 1: ```python from xarray import DataArray from numpy import zeros, ones, arange Two arrays abc and acb, identical except for dimensional orderingabc = DataArray(zeros((2, 3, 4)), dims=('a', 'b', 'c')) acb = DataArray(zeros((2, 4, 3)), dims=('a', 'c', 'b')) assert (abc == acb).all() Assign a subsetbc = DataArray(ones((3, 4)), dims=('b', 'c')) abc.loc[dict(a=0)] = bc acb.loc[dict(a=0)] = bc # ValueError: could not broadcast input array from shape (3,4) into shape (4,3) ``` Example 2: Same as example 1, but instead of raising a ValueError, runs without error, but gives incorrect results because it ignores dimension order ```python This time, make b and c dimensions identicalabc = DataArray(zeros((2, 3, 3)), dims=('a', 'b', 'c')) acb = DataArray(zeros((2, 3, 3)), dims=('a', 'c', 'b')) assert (abc == acb).all() Assign a subsetbc = DataArray(arange(9).reshape(3, 3), dims=('b', 'c')) abc.loc[dict(a=0)] = bc acb.loc[dict(a=0)] = bc assert (abc == acb).all() # Assertion error ``` MVCE confirmation
Relevant log outputNo response Anything else we need to know?No response Environment
INSTALLED VERSIONS
------------------
commit: None
python: 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:50:36) [MSC v.1929 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('English_United States', '1252')
libhdf5: 1.12.1
libnetcdf: 4.8.1
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
|
{ "url": "https://api.github.com/repos/pydata/xarray/issues/7030/reactions", "total_count": 1, "+1": 1, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
completed | 13221727 | issue |