Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`_.
Expand Down
3 changes: 1 addition & 2 deletions skops/hub_utils/_hf_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import json
import os
import shutil
import warnings
from pathlib import Path
from typing import Any, List, MutableMapping, Optional, Union

Expand Down Expand Up @@ -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)

Expand Down
13 changes: 6 additions & 7 deletions skops/hub_utils/tests/test_hf_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,26 +307,25 @@ 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}"'],
dst=dir_path,
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)


Expand Down