Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Huggingface Datasets CsvDatasetReader

From Leeroopedia
Knowledge Sources
Domains Data_Engineering, NLP
Last Updated 2026-02-14 18:00 GMT

Overview

Concrete tool for importing CSV files into the HuggingFace Dataset format provided by the HuggingFace Datasets library.

Description

CsvDatasetReader is a reader class that extends AbstractDatasetReader and uses the packaged Csv builder to parse one or more CSV files into an Arrow-backed Dataset or IterableDataset. It supports configurable features, caching, in-memory loading, streaming mode, and multiprocessing. All additional keyword arguments are forwarded to the underlying Csv builder, allowing full control over CSV dialect options (delimiter, quoting, encoding, etc.).

Usage

Use CsvDatasetReader when you need to programmatically load CSV files into a HuggingFace Dataset. It is typically invoked indirectly via Dataset.from_csv() or load_dataset("csv", ...), but can also be instantiated directly for fine-grained control.

Code Reference

Source Location

  • Repository: datasets
  • File: src/datasets/io/csv.py
  • Lines: L15-L66

Signature

class CsvDatasetReader(AbstractDatasetReader):
    def __init__(
        self,
        path_or_paths: NestedDataStructureLike[PathLike],
        split: Optional[NamedSplit] = None,
        features: Optional[Features] = None,
        cache_dir: str = None,
        keep_in_memory: bool = False,
        streaming: bool = False,
        num_proc: Optional[int] = None,
        **kwargs,
    ):

    def read(self):

Import

from datasets.io.csv import CsvDatasetReader

I/O Contract

Inputs

Name Type Required Description
path_or_paths NestedDataStructureLike[PathLike] Yes Path(s) to CSV file(s). Can be a single path, a list of paths, or a dict mapping split names to paths.
split Optional[NamedSplit] No Name of the dataset split to assign to the loaded data.
features Optional[Features] No Explicit schema to apply instead of inferring from the CSV headers and data.
cache_dir str No Directory for caching the processed dataset.
keep_in_memory bool No Whether to keep the dataset in memory instead of memory-mapping. Defaults to False.
streaming bool No If True, returns an IterableDataset for streaming access. Defaults to False.
num_proc Optional[int] No Number of processes for parallel dataset preparation.
**kwargs No Additional keyword arguments forwarded to the Csv builder (e.g., delimiter, quoting).

Outputs

Name Type Description
dataset Dataset or IterableDataset The loaded dataset, either map-style or iterable depending on the streaming parameter.

Usage Examples

Basic Usage

from datasets.io.csv import CsvDatasetReader

# Load a single CSV file
reader = CsvDatasetReader("data/train.csv", split="train")
dataset = reader.read()

# Load with streaming
reader = CsvDatasetReader("data/train.csv", streaming=True)
iterable_dataset = reader.read()

# Load with custom delimiter
reader = CsvDatasetReader("data/train.tsv", split="train", sep="\t")
dataset = reader.read()

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment