pandagg.tree.agg module

class pandagg.tree.agg.Agg(from_=None, mapping=None, identifier=None, client=None, query=None, index_name=None)[source]

Bases: pandagg.tree._tree.Tree

Tree combination of aggregation nodes.

Mapping declaration is optional, but doing so validates aggregation validity.

DEFAULT_OUTPUT = 'dataframe'
add_node(node, pid=None)[source]

If mapping is provided, nested and outnested are automatically applied.

agg(arg, insert_below=None, **kwargs)[source]

Arrange passed aggregations in arg arguments “horizontally”.

Those will be placed under the insert_below aggregation clause id if provided, else under the deepest linear bucket aggregation if there is no ambiguity: OK: A──> B ─> C ─> arg KO: A──> B

└──> C

arg argument accepts single occurrence or sequence of following formats: - string (for terms agg concise declaration) - regular Elasticsearch dict syntax - AggNode instance (for instance Terms, Filters etc)

Parameters:
  • arg – aggregation(s) clauses to insert “horizontally”
  • insert_below – parent aggregation id under which these aggregations should be placed
  • kwargs – agg body arguments when using “string” syntax for terms aggregation
Return type:

pandagg.agg.Agg

applied_nested_path_at_node(nid)[source]
bind(client, index_name=None)[source]
deepest_linear_bucket_agg

Return deepest bucket aggregation node (pandagg.nodes.abstract.BucketAggNode) of that aggregation that neither has siblings, nor has an ancestor with siblings.

classmethod deserialize(from_)[source]
execute(index=None, output='dataframe', **kwargs)[source]
groupby(by, insert_below=None, insert_above=None, **kwargs)[source]

Arrange passed aggregations in by arguments “vertically” (nested manner), above or below another agg clause.

Given the initial aggregation: A──> B └──> C

If insert_below = ‘A’: A──> by──> B

└──> C

If insert_above = ‘B’: A──> by──> B └──> C

by argument accepts single occurrence or sequence of following formats: - string (for terms agg concise declaration) - regular Elasticsearch dict syntax - AggNode instance (for instance Terms, Filters etc)

If insert_below nor insert_above is provided by will be placed between the the deepest linear bucket aggregation if there is no ambiguity, and its children: A──> B : OK generates A──> B ─> C ─> by

A──> B : KO, ambiguous, must precise either A, B or C └──> C

Parameters:
  • by – aggregation(s) clauses to insert “vertically”
  • insert_below – parent aggregation id under which these aggregations should be placed
  • insert_above – aggregation id above which these aggregations should be placed
  • kwargs – agg body arguments when using “string” syntax for terms aggregation
Return type:

pandagg.agg.Agg

node_class

alias of pandagg.node.agg.abstract.AggNode

paste(nid, new_tree, deep=False)[source]

Pastes a tree handling nested implications if mapping is provided. The provided tree should be validated beforehands.

query(query, validate=False, **kwargs)[source]
query_dict(from_=None, depth=None, with_name=True)[source]
serialize_response(aggs, output, **kwargs)[source]
set_mapping(mapping)[source]
validate_tree(exc=False)[source]

Validate tree definition against defined mapping. :param exc: if set to True, will raise exception if tree is invalid :return: boolean