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

Function drop_missing_dims

xarray/namedarray/utils.py:111–150  ·  view source on GitHub ↗

Depending on the setting of missing_dims, drop any dimensions from supplied_dims that are not present in dims. Parameters ---------- supplied_dims : Iterable of Hashable dims : Iterable of Hashable missing_dims : {"raise", "warn", "ignore"}

(
    supplied_dims: Iterable[_Dim],
    dims: Iterable[_Dim],
    missing_dims: ErrorOptionsWithWarn,
)

Source from the content-addressed store, hash-verified

109
110
111def drop_missing_dims(
112 supplied_dims: Iterable[_Dim],
113 dims: Iterable[_Dim],
114 missing_dims: ErrorOptionsWithWarn,
115) -> _DimsLike:
116 """Depending on the setting of missing_dims, drop any dimensions from supplied_dims that
117 are not present in dims.
118
119 Parameters
120 ----------
121 supplied_dims : Iterable of Hashable
122 dims : Iterable of Hashable
123 missing_dims : {"raise", "warn", "ignore"}
124 """
125
126 if missing_dims == "raise":
127 supplied_dims_set = {val for val in supplied_dims if val is not ...}
128 if invalid := supplied_dims_set - set(dims):
129 raise ValueError(
130 f"Dimensions {invalid} do not exist. Expected one or more of {dims}"
131 )
132
133 return supplied_dims
134
135 elif missing_dims == "warn":
136 if invalid := set(supplied_dims) - set(dims):
137 warnings.warn(
138 f"Dimensions {invalid} do not exist. Expected one or more of {dims}",
139 stacklevel=2,
140 )
141
142 return [val for val in supplied_dims if val in dims or val is ...]
143
144 elif missing_dims == "ignore":
145 return [val for val in supplied_dims if val in dims or val is ...]
146
147 else:
148 raise ValueError(
149 f"Unrecognised option {missing_dims} for missing_dims argument"
150 )
151
152
153def infix_dims(

Callers 1

infix_dimsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…