use of water.rapids.Val in project h2o-3 by h2oai.
the class AstMatchTest method testMatchStrList.
@Test
public void testMatchStrList() throws Exception {
final Frame data = makeTestFrame();
Frame output = null;
try {
String rapids = "(tmp= tst (match (cols data [1]) [\"sD\",\"sC\",\"sB\"] -1 ignored))";
Val val = Rapids.exec(rapids);
output = val.getFrame();
assertVecEquals(data.vec(0), output.vec(0), 0.0);
} finally {
data.delete();
if (output != null) {
output.delete();
}
}
}
use of water.rapids.Val in project h2o-3 by h2oai.
the class AstGrepTest method testGrep_outputLogical.
@Test
public void testGrep_outputLogical() throws Exception {
final Frame data = makeTestFrame();
Frame output = null;
try {
String rapids = "(tmp= tst (grep (cols data [" + _col + "]) \"" + _regex + "\" " + _ignoreCase + " " + _invert + " 1))";
Val val = Rapids.exec(rapids);
output = val.getFrame();
assertVecEquals(data.vec(0), output.vec(0), 0.0);
} finally {
data.delete();
if (output != null) {
output.delete();
}
}
}
use of water.rapids.Val in project h2o-3 by h2oai.
the class AstMomentTest method vectimeTest.
@Test
public void vectimeTest() {
Scope.enter();
try {
Session session = new Session();
new TestFrameBuilder().withName("$fr", session).withColNames("day", "hour", "min").withDataForCol(0, ard(1, 1.1, 1.2, 2, 3)).withDataForCol(1, ard(0, Double.NaN, 11, 13, 15)).withDataForCol(2, ar(0, 0, 30, 0, 0)).build();
Val result = Rapids.exec("(moment 2016 12 (cols $fr 'day') 0 0 0 0)->$res1", session);
assertTrue(result.isFrame());
Frame fr = result.getFrame();
Scope.track(fr);
assertEquals(1, fr.numCols());
assertEquals(5, fr.numRows());
assertEquals(Vec.T_TIME, fr.vec(0).get_type());
long t0 = (long) fr.vec(0).at(0);
long t1 = (long) fr.vec(0).at(1);
long t2 = (long) fr.vec(0).at(2);
long t3 = (long) fr.vec(0).at(3);
long t4 = (long) fr.vec(0).at(4);
assertEquals(0, t0 - t1);
assertEquals(0, t1 - t2);
assertEquals(24 * 3600 * 1000, t3 - t2);
assertEquals(24 * 3600 * 1000, t4 - t3);
result = Rapids.exec("(moment 2016 12 1 (cols $fr 'hour') (cols $fr 'min') 0 0)->$res2", session);
assertTrue(result.isFrame());
fr = result.getFrame();
Scope.track(fr);
assertEquals(1, fr.numCols());
assertEquals(5, fr.numRows());
assertEquals(Vec.T_TIME, fr.vec(0).get_type());
double d0 = fr.vec(0).at(0);
double d1 = fr.vec(0).at(1);
double d2 = fr.vec(0).at(2);
double d3 = fr.vec(0).at(3);
double d4 = fr.vec(0).at(4);
assertTrue("d1 should have been NaN, got " + d1 + " instead", Double.isNaN(d1));
assertEquals((11 * 60 + 30) * 60 * 1000, (long) (d2 - d0));
assertEquals((13 * 60) * 60 * 1000, (long) (d3 - d0));
assertEquals((15 * 60) * 60 * 1000, (long) (d4 - d0));
} finally {
Scope.exit();
}
}
use of water.rapids.Val in project h2o-3 by h2oai.
the class AstMomentTest method naTest.
@Test
public void naTest() {
Scope.enter();
try {
Val result = Rapids.exec("(moment 2000 1 1 0 0 0 NaN)->$f1");
assertTrue(result.isFrame());
Frame fr = result.getFrame();
Scope.track(fr);
assertEquals(1, fr.numCols());
assertEquals(1, fr.numRows());
assertEquals(Vec.T_TIME, fr.vec(0).get_type());
assertTrue(Double.isNaN(fr.vec(0).at(0)));
Session s = new Session();
new TestFrameBuilder().withName("$year", s).withColNames("year").withDataForCol(0, ard(2000, 2004, 2008)).build();
result = Rapids.exec("(moment $year 1 1 0 0 NaN 0)->$f2", s);
assertTrue(result.isFrame());
fr = result.getFrame();
Scope.track(fr);
assertEquals(1, fr.numCols());
assertEquals(3, 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)));
assertTrue(Double.isNaN(fr.vec(0).at(2)));
new TestFrameBuilder().withName("$day", s).withColNames("day").withDataForCol(0, ard(28, 29, 30)).build();
result = Rapids.exec("(moment 2001 2 $day 0 0 0 0)->$f3", s);
assertTrue(result.isFrame());
fr = result.getFrame();
Scope.track(fr);
assertEquals(1, fr.numCols());
assertEquals(3, 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)));
assertTrue(Double.isNaN(fr.vec(0).at(2)));
} finally {
Scope.exit();
}
}
use of water.rapids.Val in project h2o-3 by h2oai.
the class AstGetrowTest method TestGetrow.
/** Test that in normal case the result has the correct type and value. */
@Test
public void TestGetrow() {
Frame f = null;
try {
f = ArrayUtils.frame(ar("A", "B", "C", "D", "E"), ard(1.0, -3, 12, 1000000, Double.NaN));
Val v = Rapids.exec("(getrow " + f._key + ")");
assertTrue(v instanceof ValRow);
double[] row = v.getRow();
assertEquals(row.length, 5);
assertArrayEquals(ard(1.0, -3, 12, 1000000, Double.NaN), row, 1e-8);
} finally {
if (f != null)
f.delete();
}
}
Aggregations