home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 1445905299

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
1445905299 I_kwDOAMm_X85WLsOT 7282 groupby and mean on a MultiIndex level raises ValueError 25231875 closed 0     4 2022-11-11T19:15:58Z 2023-10-30T09:18:54Z 2023-08-31T03:50:33Z NONE      

What happened?

After using set_index to create a MultiIndex, calling groupby on a MultiIndex level and then mean raises an error.

What did you expect to happen?

Apply mean to groups, no error.

Minimal Complete Verifiable Example

Python d = DataArray( data=[ [0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13], [14, 15, 16, 17, 18, 19, 20] ], coords={ "greek": ("a", ['alpha', 'beta', 'gamma']), "colors": ("a", ['red', 'green', 'blue']), "compass": ("b", ['north', 'south', 'east', 'west', 'northeast', 'southeast', 'southwest']), "integer": ("b", [0, 1, 2, 3, 4, 5, 6]), }, dims=("a", "b") ) d = d.set_index(a=['greek', 'colors'], b=['compass', 'integer']) g = d.groupby('greek') m = g.mean(...)

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 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.10/site-packages/xarray/core/_aggregations.py", line 5698, in mean return self.reduce( File "/usr/local/lib/python3.10/site-packages/xarray/core/groupby.py", line 1201, in reduce return self.map(reduce_array, shortcut=shortcut) File "/usr/local/lib/python3.10/site-packages/xarray/core/groupby.py", line 1104, in map return self._combine(applied, shortcut=shortcut) File "/usr/local/lib/python3.10/site-packages/xarray/core/groupby.py", line 1136, in _combine index, index_vars = create_default_index_implicit(coord) File "/usr/local/lib/python3.10/site-packages/xarray/core/indexes.py", line 1045, in create_default_index_implicit index = PandasMultiIndex(array, name) File "/usr/local/lib/python3.10/site-packages/xarray/core/indexes.py", line 615, in __init__ raise ValueError( ValueError: conflicting multi-index level name 'greek' with dimension 'greek'

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.10.7 (main, Sep 13 2022, 14:31:33) [GCC 10.2.1 20210110] python-bits: 64 OS: Linux OS-release: 5.15.49-linuxkit machine: x86_64 processor: byteorder: little LC_ALL: None LANG: C.UTF-8 LOCALE: ('en_US', 'UTF-8') libhdf5: None libnetcdf: None xarray: 2022.11.0 pandas: 1.5.1 numpy: 1.23.4 scipy: None netCDF4: None pydap: None h5netcdf: None h5py: None Nio: None zarr: None cftime: None nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: None distributed: None matplotlib: None cartopy: None seaborn: None numbagg: None fsspec: None cupy: None pint: None sparse: None flox: None numpy_groupies: None setuptools: 63.2.0 pip: 22.2.2 conda: None pytest: None IPython: None sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/7282/reactions",
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 4 rows from issues_id in issues_labels
  • 2 rows from issue in issue_comments
Powered by Datasette · Queries took 314.757ms · About: xarray-datasette