Jakub
Initial commit: table-comparator
531d507
Raw History Blame Contribute Delete
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)}"
)