Skip to content
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

".indexes" not updated when setting values through ".values" #3621

Closed
kefirbandi opened this issue Dec 14, 2019 · 1 comment
Closed

".indexes" not updated when setting values through ".values" #3621

kefirbandi opened this issue Dec 14, 2019 · 1 comment

Comments

@kefirbandi
Copy link
Contributor

MCVE Code Sample

import xarray as xr

da1 = xr.DataArray([1,2],dims=['x'],coords={'x':[0,1]})

print(da1.indexes)
da1['x'].values = [1,2]
print(da1.indexes)
print('--------')
print(da1['x'])

>>> x: Int64Index([0, 1], dtype='int64', name='x')
    x: Int64Index([0, 1], dtype='int64', name='x')
    --------
    <xarray.DataArray 'x' (x: 2)>
    array([1, 2])
    Coordinates:
      * x        (x) int32 1 2

Expected Output

x: Int64Index([0, 1], dtype='int64', name='x')
x: Int64Index([1, 2], dtype='int64', name='x')
--------
<xarray.DataArray 'x' (x: 2)>
array([1, 2])
Coordinates:
  * x        (x) int32 1 2

Problem Description

  • .indexes gets out of sync with the values stored in the array
  • this is unfortunate as alignment with other array is done through .indexes

The issue does not occur if I
a, either do not call ".indexes" before setting the value, or
b, call da1['x'] = [1,2] instead of da1['x'].values = [1,2]

Output of xr.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 22:01:29) [MSC v.1900 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None libhdf5: 1.10.5 libnetcdf: 4.6.3 xarray: 0.14.1 pandas: 0.25.1 numpy: 1.17.1 scipy: 1.3.1 netCDF4: 1.5.2 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: None cftime: 1.0.3.4 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2.4.0 distributed: 2.5.1 matplotlib: 3.1.1 cartopy: None seaborn: 0.9.0 numbagg: None setuptools: 41.2.0 pip: 19.2.3 conda: None pytest: 5.1.2 IPython: 7.8.0 sphinx: 2.2.0
@dcherian
Copy link
Contributor

closing in favour of #3470 . Please use da1.assign_coords or da1["x"] = ... instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants