Stratify¶
- detroit.stratify() Stratify¶
Builds a new stratify operator with the default settings.
- Returns:
Stratify object
- Return type:
- class detroit.hierarchy.stratify.Stratify¶
Stratify operator
- __call__(data: list[dict[str, Any]]) Node¶
Generates a new hierarchy from the specified tabular data.
- Parameters:
data (list[dict[str, Any]]) – Data
- Returns:
Node object
- Return type:
- set_id(id_func: Callable[[Node, int, list[dict[str, Any]]], str]) Stratify¶
Sets the id accessor to the given function and returns this stratify operator.
- Parameters:
id_func (Callable[[Node, int, list[dict[str, Any]]], str]) –
Function to call which takes as argument:
node (
Node) - the descendant nodei (
int) - the index of the descendant nodedata (
list[dict[str, Any]]) - Data
It should return an ID for the node’s relationships in the conjuction with the parent ID.
- Returns:
Itself
- Return type:
- set_parent_id(parent_id: Callable[[Node, int, list[dict[str, Any]]], str]) Stratify¶
Sets the parent id accessor to the given function and returns this stratify operator.
- Parameters:
parent_id (Callable[[Node, int, list[dict[str, Any]]], str]) –
Function to call which takes as argument:
node (
Node) - the descendant nodei (
int) - the index of the descendant nodedata (
list[dict[str, Any]]) - Data
It should return an parent ID for the node’s relationships in the conjuction with the ID.
- Returns:
Itself
- Return type:
- set_path(path: Callable[[Node, int, list[dict[str, Any]]], str]) Stratify¶
Sets the
pathaccessor to the given function and returns this stratify operator.If a
pathaccessor is set, theidandparent_idaccessors are ignored, and a unix-like hierarchy is computed on the slash-delimited strings returned by the path accessor, imputing parent nodes and ids as necessary.