from pathlib import Path import csv def load(dataset_path: Path) -> dict: """ Load a dataset from a CSV file. Args: dataset_path (Path): The path to the CSV file. Returns: dict: A dictionary containing the dataset where each key is a column name and the values are lists of column values. Raises: FileNotFoundError: If the file does not exist. ValueError: If the file is not in CSV format. """ if not dataset_path.exists(): raise FileNotFoundError(f"The file {dataset_path} does not exist.") if dataset_path.suffix.lower() != ".csv": raise ValueError(f"The file {dataset_path} is not a CSV file.") try: with open(dataset_path, mode='r', newline='', encoding='utf-8') as csvfile: reader = csv.DictReader(csvfile) if reader.fieldnames is None: raise ValueError("The CSV file does not contain headers.") data = {field: [] for field in reader.fieldnames} for row in reader: for field in reader.fieldnames: data[field].append(row[field]) except Exception as e: raise ValueError(f"An error occurred while loading the CSV file: {e}") return data