from __future__ import annotations
from pathlib import Path
import polars as pl


def write_parquet(
    df: pl.DataFrame,
    path: str | Path,
    *,
    overwrite: bool = True,
) -> None:
    """
    Writes a Polars DataFrame to Parquet.
    """
    path = Path(path)
    path.parent.mkdir(parents=True, exist_ok=True)

    if path.exists() and not overwrite:
        raise FileExistsError(f"{path} already exists")

    df.write_parquet(path)


def write_csv(
    df: pl.DataFrame,
    path: str | Path,
    *,
    overwrite: bool = True,
) -> None:
    """
    Writes a Polars DataFrame to CSV.
    """
    path = Path(path)
    path.parent.mkdir(parents=True, exist_ok=True)

    if path.exists() and not overwrite:
        raise FileExistsError(f"{path} already exists")

    df.write_csv(path)