(self, v)
| 2148 | return val |
| 2149 | |
| 2150 | def validate_coerce(self, v): |
| 2151 | if is_none_or_typed_array_spec(v): |
| 2152 | return None |
| 2153 | elif not is_array(v): |
| 2154 | self.raise_invalid_val(v) |
| 2155 | |
| 2156 | # Save off original v value to use in error reporting |
| 2157 | orig_v = v |
| 2158 | |
| 2159 | # Convert everything into nested lists |
| 2160 | # This way we don't need to worry about nested numpy arrays |
| 2161 | v = to_scalar_or_list(v) |
| 2162 | |
| 2163 | is_v_2d = v and is_array(v[0]) |
| 2164 | |
| 2165 | if is_v_2d and self.dimensions in ("1-2", 2): |
| 2166 | if is_array(self.items): |
| 2167 | # e.g. 2D list as parcoords.dimensions.constraintrange |
| 2168 | # check that all items are there for each nested element |
| 2169 | for i, row in enumerate(v): |
| 2170 | # Check row length |
| 2171 | if not is_array(row) or len(row) != len(self.items): |
| 2172 | self.raise_invalid_val(orig_v[i], [i]) |
| 2173 | |
| 2174 | for j, validator in enumerate(self.item_validators): |
| 2175 | row[j] = self.validate_element_with_indexed_name( |
| 2176 | v[i][j], validator, [i, j] |
| 2177 | ) |
| 2178 | else: |
| 2179 | # e.g. 2D list as layout.grid.subplots |
| 2180 | # check that all elements match individual validator |
| 2181 | validator = self.item_validators[0] |
| 2182 | for i, row in enumerate(v): |
| 2183 | if not is_array(row): |
| 2184 | self.raise_invalid_val(orig_v[i], [i]) |
| 2185 | |
| 2186 | for j, el in enumerate(row): |
| 2187 | row[j] = self.validate_element_with_indexed_name( |
| 2188 | el, validator, [i, j] |
| 2189 | ) |
| 2190 | elif v and self.dimensions == 2: |
| 2191 | # e.g. 1D list passed as layout.grid.subplots |
| 2192 | self.raise_invalid_val(orig_v[0], [0]) |
| 2193 | elif not is_array(self.items): |
| 2194 | # e.g. 1D list passed as layout.grid.xaxes |
| 2195 | validator = self.item_validators[0] |
| 2196 | for i, el in enumerate(v): |
| 2197 | v[i] = self.validate_element_with_indexed_name(el, validator, [i]) |
| 2198 | |
| 2199 | elif not self.free_length and len(v) != len(self.item_validators): |
| 2200 | # e.g. 3 element list as layout.xaxis.range |
| 2201 | self.raise_invalid_val(orig_v) |
| 2202 | elif self.free_length and len(v) > len(self.item_validators): |
| 2203 | # e.g. 4 element list as layout.updatemenu.button.args |
| 2204 | self.raise_invalid_val(orig_v) |
| 2205 | else: |
| 2206 | # We have a 1D array of the correct length |
| 2207 | for i, (el, validator) in enumerate(zip(v, self.item_validators)): |
nothing calls this directly
no test coverage detected