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,
)
| 109 | |
| 110 | |
| 111 | def 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 | |
| 153 | def infix_dims( |
no outgoing calls
no test coverage detected
searching dependent graphs…