MCPcopy Index your code
hub / github.com/pydata/xarray / _parse_dim

Method _parse_dim

xarray/core/groupby.py:1033–1062  ·  view source on GitHub ↗
(self, dim: Dims)

Source from the content-addressed store, hash-verified

1031 return obj
1032
1033 def _parse_dim(self, dim: Dims) -> tuple[Hashable, ...]:
1034 parsed_dim: tuple[Hashable, ...]
1035 if isinstance(dim, str):
1036 parsed_dim = (dim,)
1037 elif dim is None:
1038 parsed_dim_list = list()
1039 # preserve order
1040 for dim_ in itertools.chain(
1041 *(grouper.codes.dims for grouper in self.groupers)
1042 ):
1043 if dim_ not in parsed_dim_list:
1044 parsed_dim_list.append(dim_)
1045 parsed_dim = tuple(parsed_dim_list)
1046 elif dim is ...:
1047 parsed_dim = tuple(self._original_obj.dims)
1048 else:
1049 parsed_dim = tuple(dim)
1050
1051 # Do this so we raise the same error message whether flox is present or not.
1052 # Better to control it here than in flox.
1053 for grouper in self.groupers:
1054 if any(
1055 d not in grouper.codes.dims and d not in self._original_obj.dims
1056 for d in parsed_dim
1057 ):
1058 # TODO: Not a helpful error, it's a sanity check that dim actually exist
1059 # either in self.groupers or self._original_obj
1060 raise ValueError(f"cannot reduce over dimensions {dim}.")
1061
1062 return parsed_dim
1063
1064 def _flox_reduce(
1065 self,

Callers 2

_flox_reduceMethod · 0.95
_flox_scanMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected