atoti_query.query_level module#
- class atoti_query.QueryLevel#
-
- isin(*members)#
Return a condition to check that the level is on one of the given members.
level.isin(a, b)
is equivalent to(level == a) | (level == b)
.- Parameters:
members (ConstantValue) – One or more members on which the level should be.
- Return type:
Condition[LevelCoordinates, Literal[‘isin’], Constant, None]
Example
>>> df = pd.DataFrame( ... columns=["City", "Price"], ... data=[ ... ("Berlin", 150.0), ... ("London", 240.0), ... ("New York", 270.0), ... ("Paris", 200.0), ... ], ... ) >>> table = session.read_pandas( ... df, keys=["City"], table_name="isin example" ... ) >>> cube = session.create_cube(table) >>> l, m = cube.levels, cube.measures >>> m["Price.SUM in London and Paris"] = tt.filter( ... m["Price.SUM"], l["City"].isin("London", "Paris") ... ) >>> cube.query( ... m["Price.SUM"], ... m["Price.SUM in London and Paris"], ... levels=[l["City"]], ... ) Price.SUM Price.SUM in London and Paris City Berlin 150.00 London 240.00 240.00 New York 270.00 Paris 200.00 200.00
- isnull()#
Return a condition evaluating to
True
when a level is not expressed in a query andFalse
otherwise.Use ~level.isnull() for the opposite behavior.
Example
>>> df = pd.DataFrame( ... columns=["Country", "City", "Price"], ... data=[ ... ("France", "Paris", 200.0), ... ("Germany", "Berlin", 120), ... ], ... ) >>> table = session.read_pandas(df, table_name="isnull example") >>> cube = session.create_cube(table) >>> l, m = cube.levels, cube.measures >>> m["City.isnull"] = l["City"].isnull() >>> m["City.notnull"] = ~l["City"].isnull() >>> cube.query( ... m["City.isnull"], ... m["City.notnull"], ... levels=[l["Country"], l["City"]], ... include_totals=True, ... ) City.isnull City.notnull Country City Total True False France True False Paris False True Germany True False Berlin False True
- Return type:
Condition[LevelCoordinates, Literal[‘eq’], None, None]