Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

surfacing a problem in current LoadHF #1599

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/library/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest.mock import patch

import pandas as pd
from datasets import Dataset, DatasetDict, IterableDataset, IterableDatasetDict
from unitxt.error_utils import UnitxtError
from unitxt.loaders import (
LoadCSV,
Expand Down Expand Up @@ -232,6 +233,23 @@ def test_load_from_HF_multiple_innvocation_with_filter(self):
) # that HF dataset only has the 'test' split
self.assertEqual(instance["language"], "eng")

def test_load_HF_lazily(self):
lazy_loader = LoadHF(path="ibm/finqa", streaming=True)
dataset = lazy_loader.load_dataset(split="test")
self.assertIsInstance(dataset, (Dataset, IterableDataset))
# we just assured that load_dataset completed OK, having changed the streaming from True to False
# now we try to touch the arriving dataset, which in current main is only done by the split generator when yielding
first_example = next(iter(dataset))
self.assertIsNotNone (first_example)
# the same goes when split=None:
dataset = lazy_loader.load_dataset(split=None)
self.assertIsInstance(dataset, (DatasetDict, IterableDatasetDict))
# we just assured that load_dataset completed OK, having changed to streaming=False
# now we try to touch the samples in the arriving dataset, which in current main is only done by the split generator when yielding
for k in dataset.keys():
first_example = next(iter(dataset[k]))
self.assertIsNotNone (first_example)

def test_load_from_HF_split(self):
loader = LoadHF(path="sst2", split="train")
ms = loader()
Expand Down
4 changes: 2 additions & 2 deletions utils/.secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@
"filename": "tests/library/test_loaders.py",
"hashed_secret": "8d814baafe5d8412572dc520dcab83f60ce1375c",
"is_verified": false,
"line_number": 125,
"line_number": 126,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": "tests/library/test_loaders.py",
"hashed_secret": "42a472ac88cd8d43a2c5ae0bd0bdf4626cdaba31",
"is_verified": false,
"line_number": 135,
"line_number": 136,
"is_secret": false
}
]
Expand Down
Loading