home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 1600983717

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
1600983717 I_kwDOAMm_X85fbRKl 7563 MultiIndex coordinates do not exist updating v2022.3 to v2022.12 29361544 closed 0     1 2023-02-27T11:17:34Z 2023-08-29T14:23:30Z 2023-08-29T14:23:30Z NONE      

What happened?

Hi, thank you all for this amazing tool and its capabilities.

I noticed my code breaking from an update of xarray of v2022.3 to v2022.12 I wanted to select the latitude inside the MultiIndex position=(lat, lon) but in the new version it doesn't seem to exist when I overwrite an existing index. It works though, when the DataArray is created with the MultiIndex in the first place.

See the code example below. In the meantime I will use xarray v2022.3 Thank you!

What did you expect to happen?

In v2022.3 the output would be (selecting latitudes)

```python

da.lat <xarray.DataArray 'lat' (position: 4)> array([0.1, 0.2, 0.7, 0.9]) Coordinates: * position (position) MultiIndex - lat (position) float64 0.1 0.2 0.7 0.9 - lon (position) float64 0.1 0.2 0.7 0.9

```

Minimal Complete Verifiable Example

```Python import xarray as xr import numpy as np import pandas as pd print(xr.version)

def test_xarray_multiindex(): mda = xr.DataArray(np.random.rand(4), coords={"position": pd.Index([0.1, 0.2, 0.7, 0.9], name='position')}, dims="position") midx = pd.MultiIndex.from_arrays([[0.1, 0.2, 0.7, 0.9], [0.1, 0.2, 0.7, 0.9]], names=("lat", "lon")) mda['position'] = midx print(mda.lat) # <-- raises Error in xarray 2022.12

test_xarray_multiindex() ```

MVCE confirmation

  • [X] Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • [X] Complete example — the example is self-contained, including all data and the text of any traceback.
  • [X] Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • [X] New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

```Python AttributeError Traceback (most recent call last) Cell In[1], line 16 13 print(mda) 14 print(mda.lat) # <-- raises Error in some xr versions ---> 16 test_xarray_multiindex()

Cell In[1], line 14, in test_xarray_multiindex() 12 mda['position'] = midx 13 print(mda) ---> 14 print(mda.lat)

File /home/swd/manual/nwp/2023.1/lib/python3.10/site-packages/xarray/core/common.py:268, in AttrAccessMixin.getattr(self, name) 266 with suppress(KeyError): 267 return source[name] --> 268 raise AttributeError( 269 f"{type(self).name!r} object has no attribute {name!r}" 270 )

AttributeError: 'DataArray' object has no attribute 'lat' ```

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.10.9 | packaged by conda-forge | (main, Feb 2 2023, 20:20:04) [GCC 11.3.0] python-bits: 64 OS: Linux OS-release: 4.18.0-372.19.1.el8_6.x86_64 machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: 1.12.2 libnetcdf: 4.8.1 xarray: 2023.2.0 pandas: 1.5.3 numpy: 1.23.5 scipy: 1.10.0 netCDF4: 1.6.2 pydap: None h5netcdf: 1.1.0 h5py: 3.8.0 Nio: None zarr: None cftime: 1.6.2 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2023.2.0 distributed: 2023.2.0 matplotlib: 3.7.0 cartopy: 0.21.1 seaborn: None numbagg: None fsspec: 2023.1.0 cupy: None pint: 0.20.1 sparse: None flox: None numpy_groupies: None setuptools: 67.3.2 pip: 23.0 conda: None pytest: None mypy: None IPython: 8.10.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/7563/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 3 rows from issues_id in issues_labels
  • 1 row from issue in issue_comments
Powered by Datasette · Queries took 0.696ms · About: xarray-datasette