-
Notifications
You must be signed in to change notification settings - Fork 2k
/
pyunit_to_H2OFrame.py
171 lines (139 loc) · 7.04 KB
/
pyunit_to_H2OFrame.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import sys
sys.path.insert(1,"../../")
import h2o
from tests import pyunit_utils
import numpy as np
import pandas as pd
def to_H2OFrame():
# TODO: negative testing
## 1. list
# a. single col
python_obj = [1, 2, 2.5, -100.9, 0]
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=1)
# b. 1 col, 5 rows
python_obj = [[1], [2], [3.7], [8], [9]]
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=1)
# c. 5 cols, 3 rows
python_obj = [[6,7,8,9,10], [1,2,3,4,5], [3,2,2,2,2]]
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=3, cols=5)
python_obj = [["a", "b"], ["c", "d"]]
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=2, cols=2)
# d. jagged
python_obj = [[6,7,8,9,10], [1,2,3,4], [3,2,2]]
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=3, cols=5, dim_only=True)
## 2. tuple
# a. single row
python_obj = (1, 1e-5, 2.5, 23, 0)
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=1)
# b. single column
python_obj = ((1,), (2,), (3.7,), (8,), (9,))
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=1)
# c. multiple rows, columns
python_obj = ((6,7,8,9,10), (1,2,3,4,5), (3,2,2,2,2))
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=3, cols=5)
# d. jagged
python_obj = ((6,7,8,9,10), (1,2,3,4), (3,2,2))
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=3, cols=5, dim_only=True)
## 3. list-tuple mixed
# a. single column
python_obj = ((1,), [2], (3.7,), [8], (9,))
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=1)
# b. single column
python_obj = [(1,), [2], (3.7,), [8], (9,)]
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=1)
# c. multiple rows, columns
python_obj = ([6,7,8,9,10], (1,2,3,4,5), [3,2,2,2,2])
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=3, cols=5)
# d. multiple rows, columns
python_obj = [(6,7,8,9,10), [1,2,3,4,5], (3,2,2,2,2)]
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=3, cols=5)
# e. jagged
python_obj = [(6,7,8,9,10), [1,2,3,4], (3,2,2)]
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=3, cols=5, dim_only=True)
# f. jagged
python_obj = ((6,7,8,9,10), [1,2,3,4], (3,2,2))
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=3, cols=5, dim_only=True)
# 4. dictionary
# a. single row
python_obj = {"a":1, "b":"a", "c":2.5, "d":"bcd", "e":0}
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=1, cols=5)
assert set(the_frame.names) == set(python_obj.keys()), "H2OFrame header is hosed. Got {0}, but should have got " \
"{1}".format(the_frame.names, python_obj.keys())
python_obj = {"a":[1], "b":["a"], "c":[2.5], "d":["bcd"], "e":[0]}
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=1, cols=5)
assert set(the_frame.names) == set(python_obj.keys()), "H2OFrame header is hosed. Got {0}, but should have got " \
"{1}".format(the_frame.names, python_obj.keys())
# b. single column
python_obj = {"foo":(1,2,3.7,8,9)}
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=1)
assert set(the_frame.names) == set(python_obj.keys()), "H2OFrame header is hosed. Got {0}, but should have got " \
"{1}".format(the_frame.names, python_obj.keys())
# c. multiple rows, columns
python_obj = {"foo":[6,7,8,9,10], "bar":(1,2,3,4,5), "baz":(3,2,2,2,2)}
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=3)
assert set(the_frame.names) == set(python_obj.keys()), "H2OFrame header is hosed. Got {0}, but should have got " \
"{1}".format(the_frame.names, python_obj.keys())
# d. jagged
python_obj = {"foo":(6,7), "bar":(1,2,3,4), "baz":(3,2,2)}
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=4, cols=3, dim_only=True)
assert set(the_frame.names) == set(python_obj.keys()), "H2OFrame header is hosed. Got {0}, but should have got " \
"{1}".format(the_frame.names, python_obj.keys())
# 5. numpy.ndarray
# a. single row
python_obj = np.array([1, "a", 2.5, "bcd", 0])
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=1)
# b. single column
python_obj = np.array([[1], [2], [3.7], [8], [9]])
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=1)
# c. multiple rows, columns
python_obj = np.array([[6,7,8,9,10], [1,2,3,4,5], [3,2,2,2,2]])
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=3, cols=5)
# d. jagged
python_obj = np.array([[6,7,8,9,10], [1,2,3,4], [3,2,2]])
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=3, cols=5)
## 6. pandas.DataFrame
# a. single row
python_obj = pd.DataFrame({'foo' : pd.Series([1]), 'bar' : pd.Series([6]), 'baz' : pd.Series(["a"]) })
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=1, cols=3)
# b. single column
python_obj = pd.DataFrame({'foo' : pd.Series([1, 2, 3, 7.8, 9])})
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=1)
# c. multiple rows, columns
python_obj = pd.DataFrame({'foo' : pd.Series([6,7,8,9,10]), 'bar' : pd.Series([1,2,3,4,5]),
'baz' : pd.Series([3,2,2,2,2])})
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=3)
# d. jagged
python_obj = pd.DataFrame({'foo' : pd.Series([6,7,8]), 'bar' : pd.Series([1,2,3,4,5]), 'baz' : pd.Series([3,2,2,2])})
the_frame = h2o.H2OFrame(python_obj)
pyunit_utils.check_dims_values(python_obj, the_frame, rows=5, cols=3)
if __name__ == "__main__":
pyunit_utils.standalone_test(to_H2OFrame)
else:
to_H2OFrame()