Spaces:
Runtime error
Runtime error
Download src/table_comparator/loader.py from reforse/table-comparator: direct link, hf CLI and curl.
- Browser
- Download file 711 Bytes
-
https://huggingface.co/spaces/reforse/table-comparator/resolve/main/src/table_comparator/loader.py
- Command line
-
hf download hf://spaces/reforse/table-comparator/src/table_comparator/loader.py
-
curl -L -o loader.py https://huggingface.co/spaces/reforse/table-comparator/resolve/main/src/table_comparator/loader.py
711 Bytes
| """File-loading utilities. Supports CSV, TSV, and Excel.""" | |
| from pathlib import Path | |
| import pandas as pd | |
| SUPPORTED_EXTENSIONS = {".csv", ".tsv", ".xlsx", ".xls"} | |
| def load_table(path: str) -> pd.DataFrame: | |
| """Load a table from *path*. Format is detected from the file extension.""" | |
| p = Path(path) | |
| if not p.exists(): | |
| raise FileNotFoundError(f"File not found: {path}") | |
| ext = p.suffix.lower() | |
| if ext == ".csv": | |
| return pd.read_csv(p) | |
| if ext == ".tsv": | |
| return pd.read_csv(p, sep="\t") | |
| if ext in (".xlsx", ".xls"): | |
| return pd.read_excel(p) | |
| raise ValueError( | |
| f"Unsupported format '{ext}'. Supported: {sorted(SUPPORTED_EXTENSIONS)}" | |
| ) | |