Skip to content

Commit

Permalink
GH-15861: fixed warning message causing code to crash. (#15862)
Browse files Browse the repository at this point in the history
* fixed warning message causing code to crash.
* shorten test to just make sure it has the correct warning message.
* put install datatable in finally in case test failed.

Co-authored-by: Marek Novotný <[email protected]>
  • Loading branch information
wendycwong and mn-mikke authored Oct 30, 2023
1 parent ac63da6 commit 936756b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions h2o-py/h2o/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1980,8 +1980,8 @@ def as_data_frame(self, use_pandas=True, header=True, multi_thread=False):
os.remove(fileName)
os.rmdir(tmpdir)
elif not(can_use_datatable()):
warnings("multi_thread mode can only be used when you have datatable "
"installed.")
warnings.warn("multi_thread mode can only be used when you have datatable "
"installed. Defaults to single-thread operation.")
return pandas.read_csv(StringIO(self.get_frame_data()), low_memory=False, skip_blank_lines=False)
from h2o.utils.csv.readers import reader
frame = [row for row in reader(StringIO(self.get_frame_data()))]
Expand Down
3 changes: 3 additions & 0 deletions h2o-py/tests/pyunit_utils/utilsPY.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ def javamunge(assembly, pojoname, test, compile_only=False):
def install(package):
subprocess.check_call([sys.executable, "-m", "pip", "install", package])

def uninstall(package):
subprocess.check_call([sys.executable, "-m", "pip", "uninstall", "-y", package])

def locate(path):
"""
Search for a relative path and turn it into an absolute path.
Expand Down
28 changes: 28 additions & 0 deletions h2o-py/tests/testdir_misc/pyunit_gh_15861_no_datatable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys
sys.path.insert(1,"../../")
import h2o
from tests import pyunit_utils
from h2o.utils.shared_utils import (can_use_datatable)

def test_datatable_without_datatable():
delTable = False
if can_use_datatable():
delTable = True
pyunit_utils.uninstall("datatable")

try:
# should run to completion
with pyunit_utils.catch_warnings() as ws:
h2oFrame = h2o.import_file(pyunit_utils.locate("bigdata/laptop/jira/PUBDEV_5266_merge_with_string_columns/PUBDEV_5266_f1.csv"))
new_frame = h2oFrame.as_data_frame(multi_thread=True)
assert "multi_thread mode can only be used when you have datatable installed. Defaults to single-thread " \
"operation." in str(ws[0].message)
finally:
# re-install datatable before quitting.
if delTable:
pyunit_utils.install("datatable")

if __name__ == "__main__":
pyunit_utils.standalone_test(test_datatable_without_datatable)
else:
test_datatable_without_datatable()

0 comments on commit 936756b

Please sign in to comment.