From 6e762c6ca0d1dbaca0cf3614b797204f9767f73e Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Fri, 20 Dec 2024 15:03:56 +0100 Subject: [PATCH] Create output directories in write_* (#352) --- petab/v1/conditions.py | 4 +++- petab/v1/core.py | 4 +++- petab/v1/mapping.py | 4 +++- petab/v1/measurements.py | 4 +++- petab/v1/observables.py | 4 +++- petab/v1/parameters.py | 4 +++- petab/v1/yaml.py | 4 +++- petab/v2/experiments.py | 4 +++- 8 files changed, 24 insertions(+), 8 deletions(-) diff --git a/petab/v1/conditions.py b/petab/v1/conditions.py index 4e691d62..5dc46565 100644 --- a/petab/v1/conditions.py +++ b/petab/v1/conditions.py @@ -60,9 +60,11 @@ def write_condition_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab condition table - filename: Destination file name + filename: Destination file name. The parent directory will be created + if necessary. """ df = get_condition_df(df) + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=True) diff --git a/petab/v1/core.py b/petab/v1/core.py index 10274b8c..3b4a4082 100644 --- a/petab/v1/core.py +++ b/petab/v1/core.py @@ -60,8 +60,10 @@ def write_simulation_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab simulation table - filename: Destination file name + filename: Destination file name. The parent directory will be created + if necessary. """ + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=False) diff --git a/petab/v1/mapping.py b/petab/v1/mapping.py index bae9d5fb..813cf7d3 100644 --- a/petab/v1/mapping.py +++ b/petab/v1/mapping.py @@ -60,9 +60,11 @@ def write_mapping_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab mapping table - filename: Destination file name + filename: Destination file name. The parent directory will be created + if necessary. """ df = get_mapping_df(df) + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=True) diff --git a/petab/v1/measurements.py b/petab/v1/measurements.py index 757ce9ce..f78511df 100644 --- a/petab/v1/measurements.py +++ b/petab/v1/measurements.py @@ -58,9 +58,11 @@ def write_measurement_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab measurement table - filename: Destination file name + filename: Destination file name. The parent directory will be created + if necessary. """ df = get_measurement_df(df) + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=False) diff --git a/petab/v1/observables.py b/petab/v1/observables.py index 1485302d..411c2a4c 100644 --- a/petab/v1/observables.py +++ b/petab/v1/observables.py @@ -67,9 +67,11 @@ def write_observable_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab observable table - filename: Destination file name + filename: Destination file name. The parent directory will be created + if necessary. """ df = get_observable_df(df) + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=True) diff --git a/petab/v1/parameters.py b/petab/v1/parameters.py index 20457dcb..c2f37f62 100644 --- a/petab/v1/parameters.py +++ b/petab/v1/parameters.py @@ -112,9 +112,11 @@ def write_parameter_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab parameter table - filename: Destination file name + filename: Destination file name. The parent directory will be created + if necessary. """ df = get_parameter_df(df) + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=True) diff --git a/petab/v1/yaml.py b/petab/v1/yaml.py index 51159453..ac134d5b 100644 --- a/petab/v1/yaml.py +++ b/petab/v1/yaml.py @@ -238,8 +238,10 @@ def write_yaml(yaml_config: dict[str, Any], filename: str | Path) -> None: Arguments: yaml_config: Data to write - filename: File to create + filename: Destination file name. The parent directory will be created + if necessary. """ + Path(filename).parent.mkdir(parents=True, exist_ok=True) with open(filename, "w") as outfile: yaml.dump( yaml_config, outfile, default_flow_style=False, sort_keys=False diff --git a/petab/v2/experiments.py b/petab/v2/experiments.py index 7833fa1f..17137b5c 100644 --- a/petab/v2/experiments.py +++ b/petab/v2/experiments.py @@ -34,7 +34,9 @@ def write_experiment_df(df: pd.DataFrame, filename: str | Path) -> None: Arguments: df: PEtab experiments table - filename: Destination file name + filename: Destination file name. The parent directory will be created + if necessary. """ df = get_experiment_df(df) + Path(filename).parent.mkdir(parents=True, exist_ok=True) df.to_csv(filename, sep="\t", index=False)