Skip to content

GroupDataArray with mask fails to calculate mean #3866

Open

Description

@YooSunYoung

We noticed this in the ymir tomography notebook that it fails to calculate mean when there is a mask.
sum works so we could use that instead.
But it's strange that sum works but no the mean.
It doesn't fail when you drop the mask.

I didn't investigate further yet so I don't know what the problem is exactly....

Reproduce Error

import scipp as sc

da = sc.data.table_xyz(nrow=100).hist(x=10, y=10, z=12)
da.coords['z'] = sc.midpoints(da.coords['z'])
da.masks['mask'] = da.data < sc.scalar(1., unit='K')
grouped = da.groupby('z', bins=sc.linspace(dim='z', start=0., stop=1., num=3, unit='m'))
grouped.mean('z')
---------------------------------------------------------------------------
DimensionError                            Traceback (most recent call last)
Cell In[53], line 7
      5 da.masks['mask'] = da.data < sc.scalar(1., unit='K')
      6 grouped = da.groupby('z', bins=sc.linspace(dim='z', start=0., stop=1., num=3, unit='m'))
----> 7 grouped.mean('z')

DimensionError: Expected 0 dimensions, got 2

Activity

  1. added theissue type on Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions