use of water.rapids.Session 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.Session 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.Session in project h2o-3 by h2oai.
the class AstTmpAssignTest method assignSameId.
@Test
public void assignSameId() {
Scope.enter();
try {
Session session = new Session();
String newid = new Env(session).expand("$frame1");
Frame f = ArrayUtils.frame(Key.<Frame>make(), ar("a", "b"), ard(1, -1), ard(2, 0), ard(3, 1));
Frame v = Rapids.exec("(tmp= $frame1 (, " + f._key + ")->$frame1)", session).getFrame();
Frame w = DKV.get(newid).get();
Scope.track(f, v);
assertEquals(newid, v._key.toString());
assertArrayEquals(f.names(), v.names());
assertNotEquals(f._key, v._key);
assertEquals(w, v);
newid = new Env(session).expand("$f");
v = Rapids.exec("(, (, $frame1)->$f)->$f", session).getFrame();
Scope.track(v);
assertEquals(newid, v._key.toString());
newid = new Env(session).expand("$g");
v = Rapids.exec("(colnames= (, $f)->$g [0 1] ['egg', 'ham'])->$g", session).getFrame();
Scope.track(v);
assertEquals(newid, v._key.toString());
assertArrayEquals(new String[] { "egg", "ham" }, v.names());
} finally {
Scope.exit();
}
}
use of water.rapids.Session 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();
}
}
Aggregations