Skip to content

Deferred imports for datasets libraries (torchvision, tensorflow-datasets, and HF datasets) - #121

Merged
y-prudent merged 4 commits into
masterfrom
feat/torchvision_lazy_import
Mar 31, 2026
Merged

Deferred imports for datasets libraries (torchvision, tensorflow-datasets, and HF datasets)#121
y-prudent merged 4 commits into
masterfrom
feat/torchvision_lazy_import

Conversation

@cofri

@cofri cofri commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

Torchvision and tensorflow-datasets (tfds) are not dependencies of oodeel. In DataHandlers, the imports for those packages are then deferred in the corresponding functions to avoid ImportError if not installed. The error will only be raised if a torchvision or tfds dataset is requested by the user.

For HuggingFace datasets library, same thing is done: the import is deferred in the load_from_huggingface function. Moreover, to be consistent with torchvision and tfds, the datasets dependency is removed from setup.py.

Solves issue #116

cofri added 2 commits January 20, 2026 10:33
torchvision is only imported when a torchvision dataset is chosen in
`load_dataset`, i.e. hub="torchvision".

As torchvision is not a dependency for oodeel, this is required to avoid
ImportError when using PyTorch backend even without a torchvision dataset.
Since tensorflow-datasets is not a dependency of oodeel, the import is
deferred in the function that loads a TF dataset. The user can now use
TFDataHandler without requiring tensorflow-datasets if not needed.
@cofri
cofri force-pushed the feat/torchvision_lazy_import branch 3 times, most recently from 8f5afdc to 5cc66f8 Compare January 20, 2026 11:24
cofri added 2 commits January 20, 2026 13:32
HuggingFace datasets package is removed from the dependencies.
Imports in TorchDataHandler and TFDataHandler is now deferred in the
corresponding functions: importing 'datasets' is only tested when a
HF dataset is chosen by the user.

Note that datasets version is set for some PyTorch versions because of
incompatibilities with other package versions...
@github-actions

github-actions Bot commented Jan 20, 2026

Copy link
Copy Markdown

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
3199 2911 91% 70% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
oodeel/datasets/tf_data_handler.py 87% 🟢
oodeel/datasets/torch_data_handler.py 89% 🟢
oodeel/types/init.py 74% 🟢
TOTAL 83% 🟢

updated for commit: ef7b3a1 by action🐍

@cofri
cofri force-pushed the feat/torchvision_lazy_import branch from b358331 to ef7b3a1 Compare January 20, 2026 12:35
@cofri
cofri marked this pull request as ready for review February 16, 2026 10:36

@y-prudent y-prudent left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM !

@y-prudent
y-prudent merged commit 12ae997 into master Mar 31, 2026
10 checks passed
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.

2 participants