Skip to content

Commit

Permalink
Merge branch 'ig/fix_extension_array_dataarray_roundtrip' of github.c…
Browse files Browse the repository at this point in the history
…om:ilan-gold/xarray into ig/fix_extension_array_dataarray_roundtrip
  • Loading branch information
ilan-gold committed Sep 19, 2024
2 parents 28e2a7b + b073404 commit bfb6b7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,10 +535,10 @@ def _replace_maybe_drop_dims(
variable: Variable,
name: Hashable | None | Default = _default,
) -> Self:
if variable.dims == self.dims and variable.shape == self.shape:
if self.sizes == variable.sizes:
coords = self._coords.copy()
indexes = self._indexes
elif variable.dims == self.dims:
elif set(self.dims) == set(variable.dims):
# Shape has changed (e.g. from reduce(..., keepdims=True)
new_sizes = dict(zip(self.dims, variable.shape, strict=True))
coords = {
Expand Down
13 changes: 13 additions & 0 deletions xarray/tests/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2919,3 +2919,16 @@ def test_gappy_resample_reductions(reduction):
# 1. lambda x: x
# 2. grouped-reduce on unique coords is identical to array
# 3. group_over == groupby-reduce along other dimensions


def test_groupby_transpose():
# GH5361
data = xr.DataArray(
np.random.randn(4, 2),
dims=["x", "z"],
coords={"x": ["a", "b", "a", "c"], "y": ("x", [0, 1, 0, 2])},
)
first = data.T.groupby("x").sum()
second = data.groupby("x").sum()

assert_identical(first, second.transpose(*first.dims))

0 comments on commit bfb6b7e

Please sign in to comment.