Stream: xarray

Topic: buggy dataset.groupby


view this post on Zulip Dhamma Kimpara (he/him) (Apr 19 2024 at 21:38):

has anyone experienced weirdness with xarray's .groupby(foo).apply(bar)? Specifically it seems to squeeze out the groupby dim in some cases and others.

I am running the same operations on two isomorphic datasets, just with different lat/lon dimensions (one deg vs quarter deg). It seems that groupby is not squeezing out the latitude dimension for the larger dataset.

If anyone is interested i have saved the two datasets in question and a little test.py at

/glade/work/dkimpara/xarray-bug

view this post on Zulip Katelyn FitzGerald (Apr 22 2024 at 14:44):

It certainly looks like there's some difference in behavior there following the indexing operation (not sure that's a common use case).

Are you looking to maintain the dimension or drop it? With the squeeze parameter in groupby set to False it reliably maintains the dimension. If you'd rather drop it, you can chain the squeeze method after the indexing.

view this post on Zulip Dhamma Kimpara (he/him) (Apr 22 2024 at 17:36):

I'd like to drop the dimension. Yes, for now I am using squeeze to get around this issue after checking that the dim hasn't been squeezed yet


Last updated: May 16 2025 at 17:14 UTC