-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: examples are now called only once per dataset and then cached
- Loading branch information
1 parent
d8e4d0b
commit a837672
Showing
3 changed files
with
37 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from pathlib import Path | ||
from typing import Iterable | ||
|
||
from fsspec import AbstractFileSystem # type: ignore | ||
from pytest import fixture | ||
from intelligence_layer.core.task import Input | ||
from intelligence_layer.evaluation.dataset.domain import Example, ExpectedOutput | ||
from intelligence_layer.evaluation.dataset.file_dataset_repository import FileSystemDatasetRepository | ||
|
||
|
||
class FileDatasetRepositoryTestWrapper(FileSystemDatasetRepository): | ||
def __init__(self, filesystem: AbstractFileSystem, root_directory: Path) -> None: | ||
super().__init__(filesystem, root_directory) | ||
self.counter = 0 | ||
|
||
def examples(self, dataset_id: str, input_type: type[Input], expected_output_type: type[ExpectedOutput]) -> Iterable[Example[Input, ExpectedOutput]]: | ||
self.counter += 1 | ||
return super().examples(dataset_id, input_type, expected_output_type) | ||
|
||
|
||
@fixture | ||
def file_data_repo_stub(temp_file_system: AbstractFileSystem) -> FileDatasetRepositoryTestWrapper: | ||
return FileDatasetRepositoryTestWrapper(temp_file_system, Path("Root")) | ||
|
||
|
||
def test_opens_files_only_once_when_reading_multiple_examples( | ||
file_data_repo_stub: FileDatasetRepositoryTestWrapper, | ||
) -> None: | ||
dataset = file_data_repo_stub.create_dataset([], "temp") | ||
|
||
file_data_repo_stub.example(dataset.id, "", str, str) | ||
file_data_repo_stub.example(dataset.id, "", str, str) | ||
|
||
assert file_data_repo_stub.counter == 1 |