atoti.Session.start_transaction()#

Session.start_transaction(scenario_name='Base')#

Start a transaction to batch several table operations.

  • It is more efficient than doing each table operation one after the other.

  • It avoids possibly incorrect intermediate states (e.g. if loading some new data requires dropping existing rows first).

Note

Some operations are not allowed during a transaction:

Parameters:

scenario_name (str) – The name of the source scenario impacted by all the table operations inside the transaction.

Return type:

Transaction

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="start_transaction example"
... )
>>> cube = session.create_cube(table)
>>> extra_df = pd.DataFrame(
...     columns=["City", "Price"],
...     data=[
...         ("Singapore", 250.0),
...     ],
... )
>>> with session.start_transaction():
...     table += ("New York", 100.0)
...     table.drop(table["City"] == "Paris")
...     table.load_pandas(extra_df)
>>> table.head().sort_index()
           Price
City
Berlin     150.0
London     240.0
New York   100.0
Singapore  250.0