Return the unique variable from a list of variables or raise MergeError. Parameters ---------- name : hashable Name for this variable. variables : list of Variable List of Variable objects, all of which go by the same name in different inputs. compat : {"
(
name: Hashable,
variables: list[Variable],
compat: CompatOptions | CombineKwargDefault = "broadcast_equals",
equals: bool | None = None,
)
| 104 | |
| 105 | |
| 106 | def unique_variable( |
| 107 | name: Hashable, |
| 108 | variables: list[Variable], |
| 109 | compat: CompatOptions | CombineKwargDefault = "broadcast_equals", |
| 110 | equals: bool | None = None, |
| 111 | ) -> tuple[bool | None, Variable]: |
| 112 | """Return the unique variable from a list of variables or raise MergeError. |
| 113 | |
| 114 | Parameters |
| 115 | ---------- |
| 116 | name : hashable |
| 117 | Name for this variable. |
| 118 | variables : list of Variable |
| 119 | List of Variable objects, all of which go by the same name in different |
| 120 | inputs. |
| 121 | compat : {"identical", "equals", "broadcast_equals", "no_conflicts", "override"}, optional |
| 122 | Type of equality check to use. |
| 123 | equals : None or bool, optional |
| 124 | corresponding to result of compat test |
| 125 | |
| 126 | Returns |
| 127 | ------- |
| 128 | Variable to use in the result. |
| 129 | |
| 130 | Raises |
| 131 | ------ |
| 132 | MergeError: if any of the variables are not equal. |
| 133 | """ |
| 134 | out = variables[0] |
| 135 | |
| 136 | if len(variables) == 1 or compat == "override": |
| 137 | return equals, out |
| 138 | |
| 139 | combine_method = None |
| 140 | |
| 141 | if compat == "minimal": |
| 142 | compat = "broadcast_equals" |
| 143 | |
| 144 | if compat == "broadcast_equals": |
| 145 | dim_lengths = broadcast_dimension_size(variables) |
| 146 | out = out.set_dims(dim_lengths) |
| 147 | |
| 148 | if compat == "no_conflicts": |
| 149 | combine_method = "fillna" |
| 150 | |
| 151 | # we return the lazy equals, so we can warn about behaviour changes |
| 152 | lazy_equals = equals |
| 153 | if equals is None: |
| 154 | compat_str = ( |
| 155 | compat._value if isinstance(compat, CombineKwargDefault) else compat |
| 156 | ) |
| 157 | assert compat_str is not None |
| 158 | # first check without comparing values i.e. no computes |
| 159 | for var in variables[1:]: |
| 160 | equals = getattr(out, compat_str)(var, equiv=lazy_array_equiv) |
| 161 | if equals is not True: |
| 162 | break |
| 163 |
no test coverage detected
searching dependent graphs…