From 28bea36e14811414a942c5017da3bcd1df86ce0e Mon Sep 17 00:00:00 2001 From: ammarcsj <70114795+ammarcsj@users.noreply.github.com> Date: Fri, 24 Nov 2023 19:28:46 +0100 Subject: [PATCH] ensure run config only saves simple types --- directlfq/lfq_manager.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/directlfq/lfq_manager.py b/directlfq/lfq_manager.py index fe5a12d..4038a37 100644 --- a/directlfq/lfq_manager.py +++ b/directlfq/lfq_manager.py @@ -89,11 +89,17 @@ def save_ion_df(ion_df, outfile_basename): def save_run_config(outfile_basename, kwargs): + simple_kwargs = {k: v for k, v in kwargs.items() if is_simple_data(v)} try: - df_configs = pd.DataFrame.from_dict(kwargs, orient='index', columns=['value']) - #add row with directlfq version + df_configs = pd.DataFrame.from_dict(simple_kwargs, orient='index', columns=['value']) + # Add row with directlfq version df_configs.loc["directlfq_version"] = directlfq.__version__ - df_configs.to_csv(f"{outfile_basename}.run_config.tsv", sep = "\t") - except: - print("Could not save run config.") + df_configs.to_csv(f"{outfile_basename}.run_config.tsv", sep="\t") + except Exception as e: + print(f"Could not save run config: {e}") + +def is_simple_data(value): + """Check if the data is a simple data type.""" + return isinstance(value, (int, float, str, bool, type(None), list)) +