atoti.comparator module¶
- atoti.comparator.ASCENDING = Comparator(_name='ASCENDING', _first_members=None)¶
Level comparator for ascending order.
The ascending order is used by default.
- class atoti.comparator.Comparator(_name, _first_members)¶
Level comparator.
- atoti.comparator.DESCENDING = Comparator(_name='DESCENDING', _first_members=None)¶
Level comparator for descending order.
Example
>>> df = pd.DataFrame( ... { ... "Date": ["2021-05-19", "2021-05-20"], ... "Product": ["TV", "Smartphone"], ... "Quantity": [12, 18], ... } ... ) >>> table = session.read_pandas(df, table_name="Sales") >>> cube = session.create_cube(table) >>> l, m = cube.levels, cube.measures >>> l["Date"].comparator == tt.comparator.ASCENDING True >>> cube.query(m["Quantity.SUM"], levels=[l["Date"]]) Quantity.SUM Date 2021-05-19 12 2021-05-20 18 >>> l["Date"].comparator = tt.comparator.DESCENDING >>> cube.query(m["Quantity.SUM"], levels=[l["Date"]]) Quantity.SUM Date 2021-05-20 18 2021-05-19 12
- atoti.comparator.first_members(*members)¶
Create a level comparator with the given first members.
Example
>>> df = pd.DataFrame( ... { ... "Product": ["TV", "Smartphone", "Computer", "Screen"], ... "Quantity": [12, 18, 50, 68], ... } ... ) >>> table = session.read_pandas(df, table_name="Products") >>> cube = session.create_cube(table) >>> l, m = cube.levels, cube.measures >>> cube.query(m["Quantity.SUM"], levels=[l["Product"]]) Quantity.SUM Product Computer 50 Screen 68 Smartphone 18 TV 12 >>> l["Product"].comparator = tt.comparator.first_members("TV", "Screen") >>> cube.query(m["Quantity.SUM"], levels=[l["Product"]]) Quantity.SUM Product TV 12 Screen 68 Computer 50 Smartphone 18
- Return type