From 0662386732946218530d054cec5d3250cafada09 Mon Sep 17 00:00:00 2001 From: Maximilian Schmeller Date: Sun, 25 Dec 2022 20:39:44 +0900 Subject: [PATCH] Support colum renaming and make argument names clearer in df_to_type_list --- tracing_interop/utils.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tracing_interop/utils.py b/tracing_interop/utils.py index 6468f59..b3c70e5 100644 --- a/tracing_interop/utils.py +++ b/tracing_interop/utils.py @@ -6,11 +6,16 @@ def row_to_type(row, type, **type_kwargs): return type(**row, **type_kwargs) -def df_to_type_list(df, type, mappers=None, **type_kwargs): - if mappers is not None: - for col, mapper in mappers.items(): +def df_to_type_list(df, type, column_value_mappers=None, column_to_field_mappings=None, **type_kwargs): + if column_value_mappers is not None: + for col, mapper in column_value_mappers.items(): df[col] = df[col].map(mapper) + if column_to_field_mappings is not None: + for col, field in column_to_field_mappings.items(): + df[field] = df[col] + del df[col] + has_idx = not isinstance(df.index, pd.RangeIndex) ret_list = []