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 376104925,MDU6SXNzdWUzNzYxMDQ5MjU=,2529,numpy.insert on DataArray may silently result in array inconsistent with its coordinates ,500246,closed,0,,,1,2018-10-31T18:33:23Z,2020-11-07T21:55:42Z,2020-11-07T21:55:42Z,CONTRIBUTOR,,,,"```python import numpy import xarray da = xarray.DataArray(numpy.arange(10*3).reshape(10, 3), dims=(""x"", ""y""), coords={""foo"": ((""x"", ""y""), numpy.arange(3*10).reshape(10,3))}) print(da.shape == da[""foo""].shape) da2 = numpy.insert(da, 3, 0, axis=0) print(da2.shape == da2[""foo""].shape) ``` #### Problem description Running the code snippet gives ``` True False ``` and does not raise any exception. In the resulting `da2`, the shape for `da2` and `da2['foo']` are different: we have changed the size of `da2` without changing the size of its corresponding `foo` coordinate. This happens silently, no exception is thrown. Inevitably, this is likely to result in problems at a later stage. #### Expected Output I would expect to get an exception, telling me that the insertion has failed because there are coordinates associated with the axis along which we are inserting values. It would be nice to have an `xarray.insert` that can handle this, for example, by forcing us to provide corresponding insertion values for the coordinates. #### Output of ``xr.show_versions()``
INSTALLED VERSIONS ------------------ commit: None python: 3.7.0.final.0 python-bits: 64 OS: Linux OS-release: 2.6.32-754.el6.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_GB.UTF-8 LOCALE: en_GB.UTF-8 xarray: 0.10.7 pandas: 0.23.2 numpy: 1.15.2 scipy: 1.1.0 netCDF4: 1.4.0 h5netcdf: 0.6.1 h5py: 2.8.0 Nio: None zarr: None bottleneck: 1.2.1 cyordereddict: None dask: 0.18.1 distributed: 1.22.0 matplotlib: 3.0.0 cartopy: 0.16.0 seaborn: 0.9.0 setuptools: 39.2.0 pip: 18.0 conda: None pytest: 3.2.2 IPython: 6.4.0 sphinx: None
","{""url"": ""https://api.github.com/repos/pydata/xarray/issues/2529/reactions"", ""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,completed,13221727,issue