home / github

Menu
  • Search all tables
  • GraphQL API

issues

Table actions
  • GraphQL API for issues

2 rows where state = "closed", type = "issue" and user = 29361544 sorted by updated_at descending

✎ View and edit SQL

This data as json, CSV (advanced)

Suggested facets: created_at (date), updated_at (date), closed_at (date)

type 1

  • issue · 2 ✖

state 1

  • closed · 2 ✖

repo 1

  • xarray 2
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 lkugler 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 xarray 13221727 issue
435170643 MDU6SXNzdWU0MzUxNzA2NDM= 2907 xr.dot result differs from np.dot lkugler 29361544 closed 0     4 2019-04-19T13:03:34Z 2019-04-19T17:51:45Z 2019-04-19T17:51:44Z NONE      

Code Sample

Hi, shouldn't the result of xr.dot be equivalent to np.dot? In np.dot I get values of ~280, and for xr.dot I get ~1100:

```python <xarray.DataArray 'models' (model name: 4)> array([283.6939 , 283.129198, 284.671649, 284.01668 ]) Coordinates: valid_time datetime64[ns] 2019-03-15T19:00:00 lat float64 45.89 lon float64 4.683 * model name (model name) |S5 'apple' 'juice' 'banana' 'milk'

<xarray.DataArray 'weights' (models: 4)> array([0.308999, 0.191562, 0.049474, 0.449983]) Coordinates: lat float64 45.89 lon float64 4.683 Dimensions without coordinates: models Now the calculation:python np.dot(models.values, weights_da.values) 283.7847051563903

xr.dot(weights_da, models, dims=['models', 'model name']) <xarray.DataArray ()> array(1135.532891) Coordinates: lat float64 45.89 lon float64 4.683 valid_time datetime64[ns] 2019-03-15T19:00:00

```

Problem description

What's going on below the surface? I mean if I create the array by hand (not from the file) I can't reproduce this. I don't think it's related to the file (as the values from the file work with numpy.dot). Something related to dask? Doing np.dot on the whole array (not just this piece here) results in a MemoryError. I'm

Thanks for any advice!

EDIT: I also tested it on python 3.7.3. xarray 0.11.3. Same result.

Output of xr.show_versions()

In [23]: xr.show_versions() /home/py_user/miniconda2/envs/v0/lib/python2.7/site-packages/distributed/config.py:20: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details. defaults = yaml.load(f) INSTALLED VERSIONS ------------------ commit: None python: 2.7.15.final.0 python-bits: 64 OS: Linux OS-release: 4.4.0-143-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8" LOCALE: None.None xarray: 0.10.9 pandas: 0.23.4 numpy: 1.16.2 scipy: 1.2.1 netCDF4: 1.4.2 h5netcdf: 0.7.1 h5py: 2.8.0 Nio: None zarr: None cftime: 1.0.3.4 PseudonetCDF: None rasterio: None iris: None bottleneck: 1.2.1 cyordereddict: 1.0.0 dask: 1.1.4 distributed: 1.26.0 matplotlib: 2.2.3 cartopy: None seaborn: 0.9.0 setuptools: 40.8.0 pip: 19.0.3 conda: None pytest: None IPython: 5.8.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/2907/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed xarray 13221727 issue

Advanced export

JSON shape: default, array, newline-delimited, object

CSV options:

CREATE TABLE [issues] (
   [id] INTEGER PRIMARY KEY,
   [node_id] TEXT,
   [number] INTEGER,
   [title] TEXT,
   [user] INTEGER REFERENCES [users]([id]),
   [state] TEXT,
   [locked] INTEGER,
   [assignee] INTEGER REFERENCES [users]([id]),
   [milestone] INTEGER REFERENCES [milestones]([id]),
   [comments] INTEGER,
   [created_at] TEXT,
   [updated_at] TEXT,
   [closed_at] TEXT,
   [author_association] TEXT,
   [active_lock_reason] TEXT,
   [draft] INTEGER,
   [pull_request] TEXT,
   [body] TEXT,
   [reactions] TEXT,
   [performed_via_github_app] TEXT,
   [state_reason] TEXT,
   [repo] INTEGER REFERENCES [repos]([id]),
   [type] TEXT
);
CREATE INDEX [idx_issues_repo]
    ON [issues] ([repo]);
CREATE INDEX [idx_issues_milestone]
    ON [issues] ([milestone]);
CREATE INDEX [idx_issues_assignee]
    ON [issues] ([assignee]);
CREATE INDEX [idx_issues_user]
    ON [issues] ([user]);
Powered by Datasette · Queries took 20.694ms · About: xarray-datasette