Skip to content

Add support to return dataset as a HF Dataset object in load_dataset()#116

Open
Kostis-S-Z wants to merge 5 commits into
mainfrom
add-hf-dataset-support
Open

Add support to return dataset as a HF Dataset object in load_dataset()#116
Kostis-S-Z wants to merge 5 commits into
mainfrom
add-hf-dataset-support

Conversation

@Kostis-S-Z

Copy link
Copy Markdown
Contributor

load_dataset() can now return datasets, also as HuggingFace datasets objects using a new return_format argument. pandas DataFrame still remains the default, so this is an optional feature added on top.

from datacollective import load_dataset                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                    
ds = load_dataset("your-dataset-id", return_format="hf")                                                                                                                                                                                                                                                          

Changes

  • New return_format="pandas" | "hf" argument on load_dataset (default "pandas", fully backward compatible). With "hf", single-split datasets return a Dataset; multi-split datasets (e.g. Common Voice) return a DatasetDict keyed by split name, driven by the dataset schema's splits field.
  • Optional dependency: the HF datasets library is relatively heavy, so in order to keep our client lightweight, it will ship as an extra, i.e. uv add / pip install "datacollective[hf]". Without it, return_format="hf" raises a MissingDependencyError with install instructions before any API call or download, so users never hit the error after pulling a large archive.
  • New hf_utils.py module: loaders are untouched and still produce DataFrames. The conversion happens post-hoc, so both formats always contain identical data. datasets is imported lazily and only referenced in type annotations under TYPE_CHECKING.
  • Docs: new "Return as HuggingFace Dataset object" section in index.md. Also added a section on how to lazily decode audio with cast_column("audio", Audio(...)) which might be useful for all the ASR / TTS datasets! Plus, a README Quick Start step, and an HF example in demo_download_and_load.py that runs only when datasets is installed.
    • Tests: 12 new tests covering the conversion DataFrame -> Dataset (single split, multi-split, category dtypes), the missing-dependency error and fail-fast ordering, argument validation, and the end-to-end load_dataset for both formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant