Stratify

detroit.stratify() Stratify

Builds a new stratify operator with the default settings.

Returns:

Stratify object

Return type:

Stratify

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:

Node

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 node

  • i (int) - the index of the descendant node

  • data (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:

Stratify

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 node

  • i (int) - the index of the descendant node

  • data (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:

Stratify

set_path(path: Callable[[Node, int, list[dict[str, Any]]], str]) Stratify

Sets the path accessor to the given function and returns this stratify operator.

If a path accessor is set, the id and parent_id accessors 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.

Parameters:

path (Callable[[Node, int, list[dict[str, Any]]], str]) –

Function to call which takes as argument:

  • node (Node) - the descendant node

  • i (int) - the index of the descendant node

  • data (list[dict[str, Any]]) - Data

It should return the path.

Returns:

Itself

Return type:

Stratify