atoti.hierarchy module#

class atoti.Hierarchy#

Hierarchy of a Cube.

A hierarchy is a sub category of a dimension and represents a precise type of data.

For example, Quarter or Week could be hierarchies in the Time dimension.

See also

Hierarchies to define one.

property dimension: str#

Name of the dimension of the hierarchy.

Note

If all the hierarchies in a dimension have their deepest level of type TIME, the dimension’s type will be set to TIME too. This can be useful for some clients such as Excel which rely on the dimension’s type to be TIME to decide whether to display date filters.

isin(*member_paths)#

Return a condition to check that the hierarchy is on one of the given members.

Considering hierarchy_1 containing level_1 and level_2, hierarchy_1.isin((a,), (b, c)) is equivalent to (level_1 == a) | ((level_1 == b) & (level_2 == c)).

Parameters:

member_paths (tuple[ConstantValue, ...]) – One or more member paths expressed as tuples on which the hierarchy should be. Each element in a tuple corresponds to a level of the hierarchy, from the shallowest to the deepest.

Return type:

Condition[HierarchyIdentifier, Literal[‘isin’], Constant, None]

Example

>>> df = pd.DataFrame(
...     columns=["Country", "City", "Price"],
...     data=[
...         ("Germany", "Berlin", 150.0),
...         ("Germany", "Hamburg", 120.0),
...         ("United Kingdom", "London", 240.0),
...         ("United States", "New York", 270.0),
...         ("France", "Paris", 200.0),
...     ],
... )
>>> table = session.read_pandas(
...     df, keys=["Country", "City"], table_name="isin example"
... )
>>> cube = session.create_cube(table)
>>> h, l, m = cube.hierarchies, cube.levels, cube.measures
>>> h["Geography"] = [l["Country"], l["City"]]
>>> m["Price.SUM in Germany and Paris"] = tt.filter(
...     m["Price.SUM"],
...     h["Geography"].isin(("Germany",), ("France", "Paris")),
... )
>>> cube.query(
...     m["Price.SUM"],
...     m["Price.SUM in Germany and Paris"],
...     levels=[l["Geography", "City"]],
... )
                        Price.SUM Price.SUM in Germany and Paris
Country        City
France         Paris       200.00                         200.00
Germany        Berlin      150.00                         150.00
               Hamburg     120.00                         120.00
United Kingdom London      240.00
United States  New York    270.00
property levels: Mapping[str, Level]#

Levels of the hierarchy.

property name: str#

Name of the hierarchy.

property slicing: bool#

Whether the hierarchy is slicing or not.

  • A regular (i.e. non-slicing) hierarchy is considered aggregable, meaning that it makes sense to aggregate data across all members of the hierarchy.

    For instance, for a Geography hierarchy, it is useful to see the worldwide aggregated Turnover across all countries.

  • A slicing hierarchy is not aggregable at the top level, meaning that it does not make sense to aggregate data across all members of the hierarchy.

    For instance, for an As of date hierarchy giving the current bank account Balance for a given date, it does not provide any meaningful information to aggregate the Balance across all the dates.

property virtual: bool#

Whether the hierarchy is virtual or not.

A virtual hierarchy is a lightweight hierarchy which does not store in memory the list of its members. It is useful for hierarchies with large cardinality.

property visible: bool#

Whether the hierarchy is visible or not.