Skip to content

Split the torch assertions out of test_dataset_to_iterable_dataset - #8531

Open
LeSingh1 wants to merge 1 commit into
huggingface:mainfrom
LeSingh1:ds-arrow-require-torch
Open

Split the torch assertions out of test_dataset_to_iterable_dataset#8531
LeSingh1 wants to merge 1 commit into
huggingface:mainfrom
LeSingh1:ds-arrow-require-torch

Conversation

@LeSingh1

Copy link
Copy Markdown

The problem

test_dataset_to_iterable_dataset fails when torch is not installed:

FAILED tests/test_arrow_dataset.py::test_dataset_to_iterable_dataset
E   ValueError: PyTorch needs to be installed to be able to return PyTorch tensors.

torch is an optional dependency, so running the suite without it is a supported configuration. It is the only test in this file that touches torch without @require_torch.

The fix

Most of the test does not need torch. It covers to_iterable_dataset(), the num_shards argument, the features round-trip, and the ValueError for too many shards. Only the final two assertions use with_format("torch").

So rather than decorate the existing test, which would have skipped that torch-free coverage as well, I moved the two torch assertions into their own @require_torch test. Everything else keeps running everywhere.

Verification

Without torch, tests/test_arrow_dataset.py goes from 1 failed / 362 passed / 61 skipped to 0 failed / 363 passed / 62 skipped — the torch-free half now passes where the whole test used to fail, and the new torch half skips. With torch installed both run exactly as before.

Companion to #8530, which is the same gap in tests/test_iterable_dataset.py. That one is a whole-test skip because the test there needs torch throughout; this one needed splitting instead.

Most of the test does not need torch: it covers to_iterable_dataset, the
num_shards argument and its ValueError. Only the last two assertions use
with_format("torch"), and without torch installed they fail the whole test.

Moving them into a @require_torch test keeps the rest running everywhere.
Decorating the existing test instead would have skipped the torch-free
coverage too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant