MCPcopy
hub / github.com/pydata/xarray / dataset_update_method

Function dataset_update_method

xarray/structure/merge.py:1194–1228  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1192
1193
1194def 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
1231def merge_data_and_coords(data_vars: DataVars, coords) -> _MergeResult:

Callers 2

updateMethod · 0.90
updateMethod · 0.90

Calls 5

merge_coreFunction · 0.85
itemsMethod · 0.80
to_base_variableMethod · 0.80
drop_varsMethod · 0.45
_replaceMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…