diff --git a/docs/changes.rst b/docs/changes.rst index ed62c90e..7236f3fe 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -22,6 +22,8 @@ v0.3 receive feedback from users. - Fix a bug that resulted in markdown tables being rendered incorrectly if entries contained line breaks. :pr:`156` by `Benjamin Bossan`_. +- Raise an error instead of warning the user if a given model file is empty. + :pr:`214` by `Adrin Jalali`_. - Use ``huggingface_hub`` v0.10.1 for model cards, drop ``modelcards`` dependency. :pr:`162` by `Benjamin Bossan`_. - Add source links to API documentation. :pr:`172` by `Ayyuce Demirbas`_. diff --git a/skops/hub_utils/_hf_hub.py b/skops/hub_utils/_hf_hub.py index 07c6c323..2c2fd323 100644 --- a/skops/hub_utils/_hf_hub.py +++ b/skops/hub_utils/_hf_hub.py @@ -8,7 +8,6 @@ import json import os import shutil -import warnings from pathlib import Path from typing import Any, List, MutableMapping, Optional, Union @@ -235,7 +234,7 @@ def _check_model_file(path: str | Path) -> Path: raise OSError(f"Model file '{path}' does not exist.") if os.path.getsize(path) == 0: - warnings.warn(f"Model file '{path}' is empty.") + raise RuntimeError(f"Model file '{path}' is empty.") return Path(path) diff --git a/skops/hub_utils/tests/test_hf_hub.py b/skops/hub_utils/tests/test_hf_hub.py index cdd5f17e..5aa229d1 100644 --- a/skops/hub_utils/tests/test_hf_hub.py +++ b/skops/hub_utils/tests/test_hf_hub.py @@ -307,17 +307,18 @@ def test_model_file_does_not_exist_raises(repo_path, config_json): path_unlink(model_path, missing_ok=True) -def test_init_empty_model_file_warns(repo_path, config_json): +def test_init_empty_model_file_errors(repo_path, config_json): # when model file is empty, warn users - model_path = repo_path / "foobar.pickle" - with open(model_path, "wb"): - pass + model_path = Path(repo_path / "foobar.pickle") + model_path.touch() dir_path = tempfile.mkdtemp() shutil.rmtree(dir_path) version = metadata.version("scikit-learn") - with pytest.warns() as rec: + with pytest.raises( + RuntimeError, match=re.escape(f"Model file '{model_path}' is empty.") + ): init( model=model_path, requirements=[f'scikit-learn="{version}"'], @@ -325,8 +326,6 @@ def test_init_empty_model_file_warns(repo_path, config_json): task="tabular-classification", data=iris.data, ) - assert len(rec) == 1 - assert rec[0].message.args[0] == f"Model file '{model_path}' is empty." path_unlink(model_path, missing_ok=True)