Skip to content

Commit

Permalink
Catch failed HF dataset loading and throw Giskard error
Browse files Browse the repository at this point in the history
  • Loading branch information
Inokinoki committed Jul 22, 2024
1 parent b169166 commit 2008e11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion giskard_vision/core/dataloaders/hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from giskard_vision.core.dataloaders.meta import MetaData
from giskard_vision.core.dataloaders.utils import flatten_dict
from giskard_vision.core.types import TypesBase
from giskard_vision.utils.errors import GiskardImportError
from giskard_vision.utils.errors import GiskardError, GiskardImportError


class DataLoaderHuggingFaceDataset(DataIteratorBase):
Expand Down Expand Up @@ -56,6 +56,8 @@ def __init__(
self.ds = self.splits[self.dataset_split]
except ImportError as e:
raise GiskardImportError(["datasets"]) from e
except Exception as e:
raise GiskardError(f"Error loading dataset `{hf_id}` with config `{hf_config}`") from e

self.meta_exclude_keys = []
self._idx_sampler = list(range(len(self)))
Expand Down
6 changes: 6 additions & 0 deletions giskard_vision/utils/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ def __init__(self, missing_packages: Union[List[str], str]) -> None:
raise ValueError(
f"{self.__class__.__name__}: takes only a list of strings, or a single string, instead {type(missing_packages)} was given"
)


class GiskardError(Exception):
def __init__(self, message: str) -> None:
super().__init__(message)
self.message = message

0 comments on commit 2008e11

Please sign in to comment.