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

Function _inverse_permutation_indices

xarray/core/groupby.py:160–183  ·  view source on GitHub ↗

Like inverse_permutation, but also handles slices. Parameters ---------- positions : list of ndarray or slice If slice objects, all are assumed to be slices. Returns ------- np.ndarray of indices or None, if no permutation is necessary.

(positions, N: int | None = None)

Source from the content-addressed store, hash-verified

158
159
160def _inverse_permutation_indices(positions, N: int | None = None) -> np.ndarray | None:
161 """Like inverse_permutation, but also handles slices.
162
163 Parameters
164 ----------
165 positions : list of ndarray or slice
166 If slice objects, all are assumed to be slices.
167
168 Returns
169 -------
170 np.ndarray of indices or None, if no permutation is necessary.
171 """
172 if not positions:
173 return None
174
175 if isinstance(positions[0], slice):
176 positions = _consolidate_slices(positions)
177 if positions == [slice(None)] or positions == [slice(0, None)]:
178 return None
179 positions = [np.arange(sl.start, sl.stop, sl.step) for sl in positions]
180 newpositions = nputils.inverse_permutation(
181 np.concatenate(tuple(p for p in positions if len(p) > 0)), N
182 )
183 return newpositions[newpositions != -1]
184
185
186class _DummyGroup(Generic[T_Xarray]):

Callers 1

_maybe_reorderFunction · 0.85

Calls 2

_consolidate_slicesFunction · 0.85
arangeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…