Skip to content

missing empty group when iterate over groupby_bins #4011

@miniufo

Description

@miniufo

When I try to iterate over the object grouped returned by groupby_bins, I found that the empty group is missing silently. Here is a simple case:

array = xr.DataArray(np.arange(4), dims='dim_0')
# one of these bins will be empty
bins = [0,4,5]
grouped = array.groupby_bins('dim_0', bins)

for i, group in enumerate(grouped):
    print(str(i)+'  '+group)

When a bin contains no samples (bin of (4, 5]), the empty group will be dropped. Then how to iterate over the full bins even when some bins contain nothing? I've read this related issue #1019.
But my case here need the correct order in grouped and empty groups need to be iterated over.

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