Skip to content

Commit 05a8001

Browse files
committed
Set h2o package as optional for non-h2o package users.
1 parent e529ffb commit 05a8001

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/sasctl/pzmm/pickle_model.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
import shutil
88
from pathlib import Path
99
from typing import Optional, Union, Any
10-
import h2o
10+
11+
try:
12+
import h2o
13+
except ImportError:
14+
h2o = None
1115

1216
from ..utils.misc import check_if_jupyter
1317

@@ -107,7 +111,12 @@ def pickle_trained_model(
107111
else:
108112
return {model_prefix + PICKLE: pickle.dumps(trained_model)}
109113
# For binary H2O models, save the binary file as a "pickle" file
110-
elif is_binary_model and pickle_path:
114+
elif is_h2o_model and is_binary_model and pickle_path:
115+
if not h2o:
116+
raise RuntimeError(
117+
"The h2o package is required to save the model as a binary h2o"
118+
"model."
119+
)
111120
h2o.save_model(
112121
model=trained_model,
113122
force=True,
@@ -116,6 +125,10 @@ def pickle_trained_model(
116125
)
117126
# For MOJO H2O models, gzip the model file and adjust the file extension
118127
elif is_h2o_model and pickle_path:
128+
if not h2o:
129+
raise RuntimeError(
130+
"The h2o package is required to save the model as a mojo model."
131+
)
119132
trained_model.save_mojo(
120133
force=True, path=pickle_path, filename=f"{model_prefix}.mojo"
121134
)

0 commit comments

Comments
 (0)