use of water.rapids.Val in project h2o-3 by h2oai.
the class AstNaOmitTest method TestNaOmit.
/** Test written by Nidhi to test that NaOmit actaully remove the rows with NAs in them. */
@Test
public void TestNaOmit() {
Frame f = null;
Frame fNew = null;
try {
f = ArrayUtils.frame(ar("A", "B"), ard(1.0, Double.NaN), ard(2.0, 23.3), ard(3.0, 3.3), ard(Double.NaN, 3.3));
String x = String.format("(na.omit %s)", f._key);
// make the call the remove NAs in frame
Val res = Rapids.exec(x);
// get frame without any NAs
fNew = res.getFrame();
// 2 rows of NAs removed.
assertEquals(f.numRows() - fNew.numRows(), 2);
} finally {
if (f != null)
f.delete();
if (fNew != null)
fNew.delete();
}
}
use of water.rapids.Val in project h2o-3 by h2oai.
the class AstCumuTest method testCumuSimple.
@Test
public void testCumuSimple() {
Scope.enter();
try {
Session sess = new Session();
new TestFrameBuilder().withName("$fr", sess).withColNames("c1", "c2", "c3", "c4").withDataForCol(0, ard(1, 1)).withDataForCol(1, ard(2, 2)).withDataForCol(2, ard(3, 3)).withDataForCol(3, ard(4, 4)).build();
Val val = Rapids.exec("(cumsum $fr 1)", sess);
Assert.assertTrue(val instanceof ValFrame);
Frame res = Scope.track(val.getFrame());
Assert.assertEquals(res.vec(0).at8(0L), 1);
Assert.assertEquals(res.vec(1).at8(0L), 3);
Assert.assertEquals(res.vec(2).at8(0L), 6);
Assert.assertEquals(res.vec(3).at8(0L), 10);
val = Rapids.exec("(cumsum $fr 0)", sess);
Assert.assertTrue(val instanceof ValFrame);
res = Scope.track(val.getFrame());
Assert.assertEquals(res.vec(0).at8(1L), 2);
Assert.assertEquals(res.vec(1).at8(1L), 4);
Assert.assertEquals(res.vec(2).at8(1L), 6);
Assert.assertEquals(res.vec(3).at8(1L), 8);
val = Rapids.exec("(cummax $fr 1)", sess);
Assert.assertTrue(val instanceof ValFrame);
res = Scope.track(val.getFrame());
Assert.assertEquals(res.vec(0).at8(0L), 1);
Assert.assertEquals(res.vec(1).at8(0L), 2);
Assert.assertEquals(res.vec(2).at8(0L), 3);
Assert.assertEquals(res.vec(3).at8(0L), 4);
} finally {
Scope.exit();
}
}
use of water.rapids.Val in project h2o-3 by h2oai.
the class AstMeanTest method testRowwiseMeanOnFrameWithTimeAndNumericColumn.
@Test
public void testRowwiseMeanOnFrameWithTimeAndNumericColumn() {
Frame fr = register(new Frame(Key.<Frame>make(), ar("t1", "i1"), aro(vt1, vi1)));
Val val = Rapids.exec("(mean " + fr._key + " 1 1)");
assertTrue(val instanceof ValFrame);
Frame res = register(val.getFrame());
assertColFrameEquals(ard(-1, -2, 0, 2, 1), res);
}
use of water.rapids.Val in project h2o-3 by h2oai.
the class AstMeanTest method testColumnwiseMeanOnEmptyFrame.
@Test
public void testColumnwiseMeanOnEmptyFrame() {
Frame fr = register(new Frame(Key.<Frame>make()));
Val val = Rapids.exec("(mean " + fr._key + " 0 0)");
assertTrue(val instanceof ValFrame);
Frame res = register(val.getFrame());
assertEquals(res.numCols(), 0);
assertEquals(res.numRows(), 0);
}
use of water.rapids.Val in project h2o-3 by h2oai.
the class AstMeanTest method testRowwiseMeanWithoutNaRmAndNonnumericColumn.
@Test
public void testRowwiseMeanWithoutNaRmAndNonnumericColumn() {
Frame fr = register(new Frame(Key.<Frame>make(), ar("i1", "d1", "d2", "d3", "s1"), aro(vi1, vd1, vd2, vd3, vs1)));
Val val = Rapids.exec("(mean " + fr._key + " 0 1)");
assertTrue(val instanceof ValFrame);
Frame res = register(val.getFrame());
assertColFrameEquals(ard(Double.NaN, Double.NaN, Double.NaN, Double.NaN, Double.NaN), res);
assertEquals("mean", res.name(0));
}
Aggregations