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

Function merge_collected

xarray/structure/merge.py:226–355  ·  view source on GitHub ↗

Merge dicts of variables, while resolving conflicts appropriately. Parameters ---------- grouped : mapping prioritized : mapping compat : str Type of equality check to use when checking for conflicts. combine_attrs : {"drop", "identical", "no_conflicts", "drop_confli

(
    grouped: dict[Any, list[MergeElement]],
    prioritized: Mapping[Any, MergeElement] | None = None,
    compat: CompatOptions | CombineKwargDefault = "minimal",
    combine_attrs: CombineAttrsOptions = "override",
    equals: dict[Any, bool] | None = None,
)

Source from the content-addressed store, hash-verified

224
225
226def merge_collected(
227 grouped: dict[Any, list[MergeElement]],
228 prioritized: Mapping[Any, MergeElement] | None = None,
229 compat: CompatOptions | CombineKwargDefault = "minimal",
230 combine_attrs: CombineAttrsOptions = "override",
231 equals: dict[Any, bool] | None = None,
232) -> tuple[dict[Hashable, Variable], dict[Hashable, Index]]:
233 """Merge dicts of variables, while resolving conflicts appropriately.
234
235 Parameters
236 ----------
237 grouped : mapping
238 prioritized : mapping
239 compat : str
240 Type of equality check to use when checking for conflicts.
241 combine_attrs : {"drop", "identical", "no_conflicts", "drop_conflicts", \
242 "override"} or callable, default: "override"
243 A callable or a string indicating how to combine attrs of the objects being
244 merged:
245
246 - "drop": empty attrs on returned Dataset.
247 - "identical": all attrs must be the same on every object.
248 - "no_conflicts": attrs from all objects are combined, any that have
249 the same name must also have the same value.
250 - "drop_conflicts": attrs from all objects are combined, any that have
251 the same name but different values are dropped.
252 - "override": skip comparing and copy attrs from the first dataset to
253 the result.
254
255 If a callable, it must expect a sequence of ``attrs`` dicts and a context object
256 as its only parameters.
257 equals : mapping, optional
258 corresponding to result of compat test
259
260 Returns
261 -------
262 Dict with keys taken by the union of keys on list_of_mappings,
263 and Variable values corresponding to those that should be found on the
264 merged result.
265 """
266 if prioritized is None:
267 prioritized = {}
268 if equals is None:
269 equals = {}
270
271 _assert_compat_valid(compat)
272 _assert_prioritized_valid(grouped, prioritized)
273
274 merged_vars: dict[Hashable, Variable] = {}
275 merged_indexes: dict[Hashable, Index] = {}
276 index_cmp_cache: dict[tuple[int, int], bool | None] = {}
277
278 for name, elements_list in grouped.items():
279 if name in prioritized:
280 variable, index = prioritized[name]
281 merged_vars[name] = variable
282 if index is not None:
283 merged_indexes[name] = index

Callers 5

_dataset_concatFunction · 0.90
merge_coordsFunction · 0.85
merge_coreFunction · 0.85

Calls 12

indexes_equalFunction · 0.90
dict_equivFunction · 0.90
emit_user_level_warningFunction · 0.90
_assert_compat_validFunction · 0.85
MergeErrorClass · 0.85
merge_attrsFunction · 0.85
unique_variableFunction · 0.85
itemsMethod · 0.80
warning_messageMethod · 0.80
getMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…