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

Raise an exception on receiving duplicate filepaths #242

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions src/cleanvision/dataset/fsspec_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def __init__(
self._filepaths = self.__get_filepaths(dataset_path)
else:
assert filepaths is not None
if len(filepaths) != len(set(filepaths)):
raise ValueError(
"Duplicate paths found in the list, please remove duplicate filepaths from the list."
sanjanag marked this conversation as resolved.
Show resolved Hide resolved
)
self._filepaths = filepaths
# here we assume all of the provided filepaths are from the same filesystem
self.fs, _ = fsspec.core.url_to_fs(self._filepaths[0], **self.storage_opts)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ def test_run_imagelab_given_filepaths(generate_local_dataset, images_per_class):
assert len(imagelab.issues) == images_per_class


def test_raise_error_given_duplicate_filepaths():
filepaths = ["/home/user/file0.jpg", "/home/user/file1.jpg", "/home/user/file0.jpg"]
with pytest.raises(ValueError, match="Duplicate paths found in the list"):
sanjanag marked this conversation as resolved.
Show resolved Hide resolved
Imagelab(filepaths=filepaths)


def test_s3_dataset(capsys, get_example_s3_filepaths):
imagelab = Imagelab(filepaths=get_example_s3_filepaths, storage_opts={"anon": True})
imagelab.find_issues(
Expand Down