Guts of the Dataset.update method. This drops a duplicated coordinates from `other` if `other` is not an `xarray.Dataset`, e.g., if it's a dict with DataArray values (GH2068, GH2180).
(dataset: Dataset, other: CoercibleMapping)
| 1192 | |
| 1193 | |
| 1194 | def dataset_update_method(dataset: Dataset, other: CoercibleMapping) -> _MergeResult: |
| 1195 | """Guts of the Dataset.update method. |
| 1196 | |
| 1197 | This drops a duplicated coordinates from `other` if `other` is not an |
| 1198 | `xarray.Dataset`, e.g., if it's a dict with DataArray values (GH2068, |
| 1199 | GH2180). |
| 1200 | """ |
| 1201 | from xarray.core.dataarray import DataArray |
| 1202 | from xarray.core.dataset import Dataset |
| 1203 | |
| 1204 | if not isinstance(other, Dataset): |
| 1205 | other = dict(other) |
| 1206 | for key, value in other.items(): |
| 1207 | if isinstance(value, DataArray): |
| 1208 | # drop conflicting coordinates |
| 1209 | coord_names = [ |
| 1210 | c |
| 1211 | for c in value.coords |
| 1212 | if c not in value.dims and c in dataset.coords |
| 1213 | ] |
| 1214 | if coord_names: |
| 1215 | value = value.drop_vars(coord_names) |
| 1216 | if isinstance(value.variable, IndexVariable): |
| 1217 | variable = value.variable.to_base_variable() |
| 1218 | value = value._replace(variable=variable) |
| 1219 | other[key] = value |
| 1220 | |
| 1221 | return merge_core( |
| 1222 | [dataset, other], |
| 1223 | compat="broadcast_equals", |
| 1224 | join="outer", |
| 1225 | priority_arg=1, |
| 1226 | indexes=dataset.xindexes, |
| 1227 | combine_attrs="override", |
| 1228 | ) |
| 1229 | |
| 1230 | |
| 1231 | def merge_data_and_coords(data_vars: DataVars, coords) -> _MergeResult: |
no test coverage detected
searching dependent graphs…