Skip to content

Conversation

@Aditya2755
Copy link

Fixes #7883

This PR adds @overload decorators to load_dataset() to help type checkers like Pylance and mypy correctly infer the return type based on the split and streaming parameters.

Changes:

  • Added typing imports (Literal, overload) to load.py
  • Added 4 @overload signatures that map argument combinations to specific return types:
    • split=None, streaming=False -> DatasetDict
    • split specified, streaming=False -> Dataset
    • split=None, streaming=True -> IterableDatasetDict
    • split specified, streaming=True -> IterableDataset

This resolves the Pylance error where to_csv() was not recognized on Dataset objects returned by load_dataset(..., split='train'), since the type checker previously saw the return type as a Union that included types without to_csv().

No runtime behavior changes - this is purely a static typing improvement.

Fixes huggingface#7883

This PR adds @overload decorators to load_dataset() to help type checkers
like Pylance and mypy correctly infer the return type based on the split
and streaming parameters.

Changes:
- Added typing imports (Literal, overload) to load.py
- Added 4 @overload signatures that map argument combinations to specific return types:
  * split=None, streaming=False -> DatasetDict
  * split specified, streaming=False -> Dataset
  * split=None, streaming=True -> IterableDatasetDict
  * split specified, streaming=True -> IterableDataset

This resolves the Pylance error where to_csv() was not recognized on Dataset
objects returned by load_dataset(..., split='train'), since the type checker
previously saw the return type as a Union that included types without to_csv().

No runtime behavior changes - this is purely a static typing improvement.
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.

Data.to_csv() cannot be recognized by pylance

1 participant