Skip to content

Commit

Permalink
add h2o.ls and respective pyunit
Browse files Browse the repository at this point in the history
  • Loading branch information
ericeckstrand committed Jun 17, 2015
1 parent fcd372f commit 8e16c25
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
23 changes: 22 additions & 1 deletion h2o-py/h2o/h2o.py
Expand Up @@ -491,6 +491,28 @@ def rapids(expr):
raise EnvironmentError("rapids expression not evaluated: {0}".format(str(result['error'])))
return result

def ls():
"""
List Keys on an H2O Cluster
:return: Returns a list of keys in the current H2O instance
"""
tmp_key = H2OFrame.py_tmp_key()
expr = "(= !{} (ls ))".format(tmp_key)
rapids(expr)
j = frame(tmp_key)
fr = j['frames'][0]
rows = fr['rows']
veckeys = fr['vec_ids']
cols = fr['columns']
colnames = [col['label'] for col in cols]
vecs=H2OVec.new_vecs(zip(colnames, veckeys), rows)
fr = H2OFrame(vecs=vecs)
fr.setNames(["keys"])
print "First 10 Keys: "
fr.show()
return as_list(fr, use_pandas=False)


def frame(frame_id):
"""
Retrieve metadata for a id that points to a Frame.
Expand All @@ -500,7 +522,6 @@ def frame(frame_id):
"""
return H2OConnection.get_json("Frames/" + urllib.quote(frame_id))


def frames():
"""
Retrieve all the Frames.
Expand Down
14 changes: 14 additions & 0 deletions h2o-py/tests/testdir_misc/pyunit_ls.py
@@ -0,0 +1,14 @@
import sys
sys.path.insert(1, "../../")
import h2o

def ls_test(ip,port):
# Connect to h2o
h2o.init(ip,port)

iris = h2o.import_frame(path=h2o.locate("smalldata/iris/iris.csv"))

h2o.ls()

if __name__ == "__main__":
h2o.run_test(sys.argv, ls_test)

0 comments on commit 8e16c25

Please sign in to comment.