atoti.Table.load_async()#
- async Table.load_async(data, /)#
Load data into the table asynchronously.
This is a non-blocking operation allowing to load data into one or more tables concurrently.
Example
>>> table = session.create_table( ... "Example", ... data_types={"key": "int", "value": "int"}, ... keys={"key"}, ... ) >>> df_1 = pd.DataFrame({"key": [1, 2], "value": [10, 20]}) >>> df_2 = pd.DataFrame({"key": [3, 4], "value": [30, 40]}) >>> df_3 = pd.DataFrame({"key": [2, 5], "value": [200, 500]})
Loading two DataFrames concurrently:
>>> import asyncio >>> async def load_df_1_and_2_concurrently(table): ... await asyncio.gather( ... table.load_async(df_1), ... table.load_async(df_2), ... ) >>> asyncio.run(load_df_1_and_2_concurrently(table)) >>> table.head().sort_index() value key 1 10 2 20 3 30 4 40 >>> table.drop()
Loading two DataFrames sequentially:
>>> async def load_df_1_and_3_sequentially(table): ... await table.load_async(df_1) ... assert table.row_count == 2 ... await table.load_async(df_3) ... assert table.row_count == 3, "df_3 should have overrode key `1` of df_1" >>> asyncio.run(load_df_1_and_3_sequentially(table)) >>> table.head().sort_index() value key 1 10 2 200 5 500 >>> table.drop()
Loading three DataFrames in a concurrent and sequential mix:
>>> async def load_df_1_and_3_sequentially_bis(table): ... await table.load_async(df_1) ... assert table.row_count >= 2 ... await table.load_async(df_3) ... assert table.row_count >= 3 >>> async def load_df_2(table): ... await table.load_async(df_2) ... assert table.row_count >= 2 >>> async def load_all(table): ... await asyncio.gather( ... load_df_1_and_3_sequentially_bis(table), ... load_df_2(table), ... ) ... assert table.row_count == 5 >>> asyncio.run(load_all(table)) >>> table.head().sort_index() value key 1 10 2 200 3 30 4 40 5 500
See also
load()
anddata_transaction()
.