Skip to content

Multidimensional Groupby --- ValueError: zip() argument 2 is longer than argument 1 #10739

@iuryt

Description

@iuryt

What is your issue?

I am trying to select a group from a multidimensional groupby.

import xarray as xr
from xarray.groupers import BinGrouper, UniqueGrouper

ds = xr.Dataset(
    {"foo": (("x", "y"), np.random.rand(4, 3))},
    coords={"x": [10, 20, 30, 40], "letters": ("x", list("abba"))},
)

groups = ds.groupby(x=BinGrouper(bins=[5, 15, 25]), letters=UniqueGrouper())

If I try groups.groups, it returns:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[34], [line 1](vscode-notebook-cell:?execution_count=34&line=1)
----> [1](vscode-notebook-cell:?execution_count=34&line=1) groups.groups

File ~/projects/active/swot_longterm_finescale/.pixi/envs/default/lib/python3.13/site-packages/xarray/core/groupby.py:824, in GroupBy.groups(self)
    822 # provided to mimic pandas.groupby
    823 if self._groups is None:
--> [824](https://vscode-remote+ssh-002dremote-002bcoonamessett.vscode-resource.vscode-cdn.net/home/iury/projects/active/swot_longterm_finescale/swot_longterm_finescale/~/projects/active/swot_longterm_finescale/.pixi/envs/default/lib/python3.13/site-packages/xarray/core/groupby.py:824)     self._groups = dict(
    825         zip(
    826             self.encoded.unique_coord.data,
    827             self.encoded.group_indices,
    828             strict=True,
    829         )
    830     )
    831 return self._groups

ValueError: zip() argument 2 is longer than argument 1

The code is the MWE, using the example from the documentation.
I am using xarray version 2025.9.0.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions