This gets called if we are applying on an array with a multidimensional group.
(self, obj)
| 1000 | return combined |
| 1001 | |
| 1002 | def _maybe_unstack(self, obj): |
| 1003 | """This gets called if we are applying on an array with a |
| 1004 | multidimensional group.""" |
| 1005 | from xarray.groupers import UniqueGrouper |
| 1006 | |
| 1007 | stacked_dim = self._stacked_dim |
| 1008 | if stacked_dim is not None and stacked_dim in obj.dims: |
| 1009 | inserted_dims = self._inserted_dims |
| 1010 | obj = obj.unstack(stacked_dim) |
| 1011 | for dim in inserted_dims: |
| 1012 | if dim in obj.coords: |
| 1013 | del obj.coords[dim] |
| 1014 | obj._indexes = filter_indexes_from_coords(obj._indexes, set(obj.coords)) |
| 1015 | elif len(self.groupers) > 1: |
| 1016 | # TODO: we could clean this up by setting the appropriate `stacked_dim` |
| 1017 | # and `inserted_dims` |
| 1018 | # if multiple groupers all share the same single dimension, then |
| 1019 | # we don't stack/unstack. Do that manually now. |
| 1020 | dims_to_unstack = self.encoded.unique_coord.dims |
| 1021 | if all(dim in obj.dims for dim in dims_to_unstack): |
| 1022 | obj = obj.unstack(*dims_to_unstack) |
| 1023 | to_drop = [ |
| 1024 | grouper.name |
| 1025 | for grouper in self.groupers |
| 1026 | if isinstance(grouper.group, _DummyGroup) |
| 1027 | and isinstance(grouper.grouper, UniqueGrouper) |
| 1028 | ] |
| 1029 | obj = obj.drop_vars(to_drop) |
| 1030 | |
| 1031 | return obj |
| 1032 | |
| 1033 | def _parse_dim(self, dim: Dims) -> tuple[Hashable, ...]: |
| 1034 | parsed_dim: tuple[Hashable, ...] |
no test coverage detected