Skip to content

Commit

Permalink
Remove a copy after stacking for a groupby.
Browse files Browse the repository at this point in the history
Upstream bug pandas-dev/pandas#12813 is fixed
  • Loading branch information
dcherian committed Mar 10, 2023
1 parent ba159bf commit f46f5d9
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions xarray/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ def _ensure_1d(
stacked_dim = "stacked_" + "_".join(map(str, orig_dims))
# these dimensions get created by the stack operation
inserted_dims = [dim for dim in group.dims if dim not in group.coords]
# the copy is necessary here, otherwise read only array raises error
# in pandas: https://github.com/pydata/pandas/issues/12813
newgroup = group.stack({stacked_dim: orig_dims}).copy()
newgroup = group.stack({stacked_dim: orig_dims})
newobj = obj.stack({stacked_dim: orig_dims})
return cast(T_Group, newgroup), newobj, stacked_dim, inserted_dims

Expand Down

0 comments on commit f46f5d9

Please sign in to comment.