Download libs/utils/io_tables.py from QPromaQ/Docking_project: direct link, hf CLI and curl.
- Browser
- Download file 878 Bytes
-
https://huggingface.co/datasets/QPromaQ/Docking_project/resolve/main/libs/utils/io_tables.py
- Command line
-
hf download hf://datasets/QPromaQ/Docking_project/libs/utils/io_tables.py
-
curl -L -o io_tables.py https://huggingface.co/datasets/QPromaQ/Docking_project/resolve/main/libs/utils/io_tables.py
878 Bytes
| from __future__ import annotations | |
| from pathlib import Path | |
| import pandas as pd | |
| def read_table(path: str | Path) -> pd.DataFrame: | |
| source = Path(path) | |
| suffix = source.suffix.lower() | |
| if suffix in {".csv", ".txt", ".tsv"}: | |
| sep = "\t" if suffix in {".tsv", ".txt"} else "," | |
| return pd.read_csv(source, sep=sep) | |
| if suffix == ".parquet": | |
| return pd.read_parquet(source) | |
| raise ValueError(f"Unsupported table format: {source}") | |
| def write_table(df: pd.DataFrame, path: str | Path) -> Path: | |
| target = Path(path) | |
| target.parent.mkdir(parents=True, exist_ok=True) | |
| suffix = target.suffix.lower() | |
| if suffix == ".csv": | |
| df.to_csv(target, index=False) | |
| elif suffix == ".parquet": | |
| df.to_parquet(target, index=False) | |
| else: | |
| raise ValueError(f"Unsupported output table format: {target}") | |
| return target | |