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

Function infix_dims

xarray/namedarray/utils.py:153–181  ·  view source on GitHub ↗

Resolves a supplied list containing an ellipsis representing other items, to a generator with the 'realized' list of all items

(
    dims_supplied: Iterable[_Dim],
    dims_all: Iterable[_Dim],
    missing_dims: ErrorOptionsWithWarn = "raise",
)

Source from the content-addressed store, hash-verified

151
152
153def infix_dims(
154 dims_supplied: Iterable[_Dim],
155 dims_all: Iterable[_Dim],
156 missing_dims: ErrorOptionsWithWarn = "raise",
157) -> Iterator[_Dim]:
158 """
159 Resolves a supplied list containing an ellipsis representing other items, to
160 a generator with the 'realized' list of all items
161 """
162 if ... in dims_supplied:
163 dims_all_list = list(dims_all)
164 if len(set(dims_all)) != len(dims_all_list):
165 raise ValueError("Cannot use ellipsis with repeated dims")
166 if list(dims_supplied).count(...) > 1:
167 raise ValueError("More than one ellipsis supplied")
168 other_dims = [d for d in dims_all if d not in dims_supplied]
169 existing_dims = drop_missing_dims(dims_supplied, dims_all, missing_dims)
170 for d in existing_dims:
171 if d is ...:
172 yield from other_dims
173 else:
174 yield d
175 else:
176 existing_dims = drop_missing_dims(dims_supplied, dims_all, missing_dims)
177 if set(existing_dims) ^ set(dims_all):
178 raise ValueError(
179 f"{dims_supplied} must be a permuted list of {dims_all}, unless `...` is included"
180 )
181 yield from existing_dims
182
183
184def either_dict_or_kwargs(

Callers 7

permute_dimsMethod · 0.90
_stack_onceMethod · 0.90
transposeMethod · 0.90
transposeMethod · 0.90
transposeMethod · 0.90
test_infix_dimsFunction · 0.90
test_infix_dims_errorsFunction · 0.90

Calls 2

drop_missing_dimsFunction · 0.85
countMethod · 0.45

Tested by 2

test_infix_dimsFunction · 0.72
test_infix_dims_errorsFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…