diff --git a/TM1py/Services/CellService.py b/TM1py/Services/CellService.py index 4d904b08..9a8a3d1f 100644 --- a/TM1py/Services/CellService.py +++ b/TM1py/Services/CellService.py @@ -45,6 +45,7 @@ abbreviate_mdx, build_cellset_from_pandas_dataframe, build_csv_from_cellset_dict, + build_dataframe_aggregate_intersections, build_dataframe_from_csv, build_mdx_and_values_from_cellset, build_mdx_from_cellset, @@ -1068,7 +1069,7 @@ def write_dataframe_async( slice_size_of_dataframe: int = 250_000, max_workers: int = 8, dimensions: Iterable[str] = None, - increment: bool = False, + increment: bool = True, sandbox_name: str = None, deactivate_transaction_log: bool = False, reactivate_transaction_log: bool = False, @@ -1083,7 +1084,7 @@ def write_dataframe_async( :param slice_size_of_dataframe: Number of rows for each DataFrame slice, e.g. 10000 :param max_workers: Max number of threads, e.g. 14 :param dimensions: - :param increment: increment or update cell values. Defaults to False. + :param increment: increment or update cell values. Defaults to True. :param sandbox_name: name of the sandbox or None :param deactivate_transaction_log: :param reactivate_transaction_log: @@ -1127,6 +1128,9 @@ async def _write_async(df: "pd.DataFrame"): return failures + if increment: + data = build_dataframe_aggregate_intersections(data, sum_numeric_duplicates=True) + exceptions = asyncio.run(_write_async(data)) if not exceptions: return diff --git a/TM1py/Utils/Utils.py b/TM1py/Utils/Utils.py index f84bbab3..dc5f5852 100644 --- a/TM1py/Utils/Utils.py +++ b/TM1py/Utils/Utils.py @@ -937,6 +937,23 @@ def build_cellset_from_pandas_dataframe( :return: a CaseAndSpaceInsensitiveTuplesDict """ + df = build_dataframe_aggregate_intersections(df, sum_numeric_duplicates) + + cellset = CaseAndSpaceInsensitiveTuplesDict( + dict(zip(df.iloc[:, :-1].itertuples(index=False, name=None), df.iloc[:, -1].values)) + ) + return cellset + + +@require_pandas +def build_dataframe_aggregate_intersections(df: "pd.DataFrame", sum_numeric_duplicates: bool = True) -> "pd.DataFrame": + """ + + param sum_numeric_duplicates: Aggregate numerical values for duplicated intersections + param df: A Dataframe, with dimension-column mapping in correct order. + + :return: A Dataframe + """ if isinstance(df.index, pd.MultiIndex): df.reset_index(inplace=True)