Skip to content

data_merge

Tools for merging data.

Attributes

COMPREHENSIVE module-attribute

COMPREHENSIVE = 'comprehensive'

Comprehensively merge the two data structures.

  • Scalars are overwritten by the new values
  • lists are merged and de-duplicated
  • dicts are recursively merged

UPDATE module-attribute

UPDATE = 'update'

Overwrite at the top level like dict.update().

Functions

comprehensive_merge

comprehensive_merge(left_val: T, right_val: T) -> T

Merges data comprehensively.

All arguments must be of the same type.

  • Scalars are overwritten by the new values
  • lists are merged and de-duplicated
  • dicts are recursively merged
PARAMETER DESCRIPTION
left_val

The item to merge into

TYPE: T

right_val

The item to merge from

TYPE: T

RETURNS DESCRIPTION
T

The merged data

freeze_data

freeze_data(obj: set | frozenset) -> frozenset
freeze_data(obj: tuple | list) -> tuple
freeze_data(
    obj: dict | OrderedDict | immutabledict,
) -> immutabledict
freeze_data(obj: str) -> str
freeze_data(obj: int) -> int
freeze_data(obj: float) -> float
freeze_data(obj: bytes) -> bytes
freeze_data(obj: Any) -> Any

Check type and recursively return a new read-only object.

merge_iterables

merge_iterables(iter1: Iterable, iter2: Iterable) -> set

Merge and de-duplicate a bunch of lists into a single list.

Order is not guaranteed.

PARAMETER DESCRIPTION
iter1

An Iterable

TYPE: Iterable

iter2

An Iterable

TYPE: Iterable

RETURNS DESCRIPTION
set

The merged, de-duplicated sequence as a set

nested_overwrite

nested_overwrite(*dicts: dict) -> dict

Merges dicts deeply.

PARAMETER DESCRIPTION
*dicts

List of dicts to merge with the first one as the base

TYPE: dict DEFAULT: ()

RETURNS DESCRIPTION
dict

The merged dict

TYPE: dict

update

update(left_val: T, right_val: T) -> T

Do a dict.update on all the dicts.