forked from PEtab-dev/libpetab-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexperiments.py
More file actions
42 lines (31 loc) · 1.14 KB
/
experiments.py
File metadata and controls
42 lines (31 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Functions operating on the PEtab experiments table."""
from pathlib import Path
import pandas as pd
__all__ = ["get_experiment_df", "write_experiment_df"]
def get_experiment_df(
experiments_file: str | pd.DataFrame | Path | None,
) -> pd.DataFrame | None:
"""
Read the provided observable file into a ``pandas.Dataframe``.
Arguments:
experiments_file: Name of the file to read from or pandas.Dataframe.
Returns:
Observable DataFrame
"""
if experiments_file is None:
return experiments_file
if isinstance(experiments_file, str | Path):
experiments_file = pd.read_csv(
experiments_file, sep="\t", float_precision="round_trip"
)
return experiments_file
def write_experiment_df(df: pd.DataFrame, filename: str | Path) -> None:
"""Write PEtab experiments table
Arguments:
df: PEtab experiments table
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)