Skip to content

Commit

Permalink
Merge pull request #402 from activeloopai/fix/hub_load_wrong_error
Browse files Browse the repository at this point in the history
Now if hub.load does not find the dataset it will properly raise an error
  • Loading branch information
davidbuniat authored Dec 30, 2020
2 parents 88ceb72 + c79b4ac commit 6f34b14
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from hub.compute import transform
from hub.log import logger
import traceback
from hub.exceptions import DaskModuleNotInstalledException
from hub.exceptions import DaskModuleNotInstalledException, HubDatasetNotFoundException


def local_mode():
Expand Down Expand Up @@ -47,6 +47,8 @@ def load(tag):
return ds
except ImportError:
raise DaskModuleNotInstalledException
except HubDatasetNotFoundException:
raise
except Exception as e:
pass
# logger.warning(traceback.format_exc() + str(e))
Expand Down
2 changes: 1 addition & 1 deletion hub/collections/dataset/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def load(tag, creds=None, session_creds=True) -> Dataset:
fs, path = _load_fs_and_path(tag, creds, session_creds=session_creds)
fs: fsspec.AbstractFileSystem = fs
path_2 = f"{path}/meta.json"
if not fs.exists(path):
if not fs.exists(path_2):
raise HubDatasetNotFoundException(tag)

with fs.open(path_2, "r") as f:
Expand Down
10 changes: 10 additions & 0 deletions hub/tests/test_hub_init.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from hub.exceptions import HubDatasetNotFoundException
import pytest

import hub
import hub.config
from hub.utils import dask_loaded
Expand All @@ -22,6 +25,13 @@ def test_load(caplog):
assert isinstance(obj, hub.Dataset) == True


def test_load_wrong_dataset():
try:
obj = hub.load("./data/dataset_that_does_not_exist")
except Exception as ex:
assert isinstance(ex, HubDatasetNotFoundException)


if __name__ == "__main__":
test_local_mode()
test_dev_mode()
Expand Down

0 comments on commit 6f34b14

Please sign in to comment.