use of water.rapids.Val in project h2o-3 by h2oai.
the class AstMomentTest method testOneRowFrame.
@Test
public void testOneRowFrame() {
Scope.enter();
try {
Session s = new Session();
new TestFrameBuilder().withName("$frame1", s).withColNames("day", "hour").withDataForCol(0, ar(1)).withDataForCol(1, ard(Double.NaN)).build();
new TestFrameBuilder().withName("$month", s).withColNames("month").withDataForCol(0, ar(2, 3)).build();
Val result = Rapids.exec("(moment 2010 $month (cols $frame1 'day') 0 0 0 0)->$res1", s);
assertTrue(result.isFrame());
Frame fr = result.getFrame();
Scope.track(fr);
assertEquals(1, fr.numCols());
assertEquals(2, fr.numRows());
assertEquals(Vec.T_TIME, fr.vec(0).get_type());
result = Rapids.exec("(moment 2010 $month 1 (cols $frame1 'hour') 0 0 0)->$res2", s);
assertTrue(result.isFrame());
fr = result.getFrame();
Scope.track(fr);
assertEquals(1, fr.numCols());
assertEquals(2, fr.numRows());
assertEquals(Vec.T_TIME, fr.vec(0).get_type());
assertTrue(Double.isNaN(fr.vec(0).at(0)));
assertTrue(Double.isNaN(fr.vec(0).at(1)));
} finally {
Scope.exit();
}
}
use of water.rapids.Val in project h2o-3 by h2oai.
the class TimeSeriesTests method testIsax.
@Test
public void testIsax() {
//
Val res1 = Rapids.exec("(cumsum " + f._key + " 1)");
fr1 = res1.getFrame();
DKV.put(fr1);
// 10 words 10 max cardinality 0 optimize card
Val res2 = Rapids.exec("(isax " + fr1._key + " 10 10 0)");
fr2 = res2.getFrame();
String expected = "0^10_0^10_0^10_0^10_5^10_7^10_8^10_9^10_9^10_8^10";
final String actual = fr2.vec(0).atStr(new BufferedString(), 0).toString();
Assert.assertEquals(expected, actual);
}
use of water.rapids.Val in project h2o-3 by h2oai.
the class AstGetrowTest method TestGetrow3.
/** Test columns of various types */
@Test
public void TestGetrow3() {
Frame f = null;
Vec[] vv = null;
try {
f = ArrayUtils.frame(ar("D1", "D2"), ard(0, 1));
vv = f.vec(0).makeCons(5, 0, ar(ar("N", "Y"), ar("a", "b", "c"), null, null, null), ar(Vec.T_CAT, Vec.T_CAT, Vec.T_TIME, Vec.T_STR, Vec.T_UUID));
f.add(ar("C1", "C2", "T1", "S1", "U1"), vv);
Val v = Rapids.exec("(getrow " + f._key + ")");
assertTrue(v instanceof ValRow);
double[] row = v.getRow();
assertEquals(7, row.length);
assertArrayEquals(ard(0, 1, Double.NaN, Double.NaN, 0, Double.NaN, Double.NaN), row, 1e-8);
} finally {
if (f != null)
f.delete();
if (vv != null)
for (Vec v : vv) v.remove();
}
}
use of water.rapids.Val in project h2o-3 by h2oai.
the class AstGetrowTest method TestGetrow2.
/** Test that an exception is thrown when number of rows in the frame is > 1. */
@Test
public void TestGetrow2() {
Frame f = null;
try {
f = ArrayUtils.frame(ard(-3, 4), ard(0, 1));
Val v2 = null;
try {
v2 = Rapids.exec("(getrow " + f._key + ")");
} catch (IllegalArgumentException ignored) {
}
assertNull("getrow is allowed only for single-row frames", v2);
} finally {
if (f != null)
f.delete();
}
}
use of water.rapids.Val in project h2o-3 by h2oai.
the class AstMeanTest method testRowwiseMeanOnFrameWithTimeColumnsOnly.
@Test
public void testRowwiseMeanOnFrameWithTimeColumnsOnly() {
Frame fr = register(new Frame(Key.<Frame>make(), ar("t1", "s", "t2"), aro(vt1, vs1, vt2)));
Val val = Rapids.exec("(mean " + fr._key + " 1 1)");
assertTrue(val instanceof ValFrame);
Frame res = register(val.getFrame());
assertEquals("Unexpected column name", "mean", res.name(0));
assertEquals("Unexpected column type", Vec.T_TIME, res.types()[0]);
assertColFrameEquals(ard(15000000, 15000020, 15000030, 15000040, 15000060), res);
}
Aggregations