Skip to content

Commit 0fa07f2

Browse files
committed
PUB-682: head of empty data frame does not throw
1 parent 7e56d5a commit 0fa07f2

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
setwd(normalizePath(dirname(R.utils::commandArgs(asValues=TRUE)$"f")))
2+
source('../findNSourceUtils.R')
3+
4+
test.head_empty_frame <- function(conn) {
5+
6+
a_initial = cbind(c(0,0,0,0), c(1,1,1,1))
7+
# create data frame without col names in R, transfer to h2o (V* names preserved from R)
8+
a.h2o <- as.h2o(conn, a_initial, key="A.hex")
9+
10+
# now we'll create an empty b.h2o in h2o
11+
b.h2o = a.h2o[a.h2o$V1==32]
12+
13+
head(b.h2o[,1])
14+
head(b.h2o[1,])
15+
16+
testEnd()
17+
}
18+
19+
doTest("Test frame add.", test.head_empty_frame)

src/main/java/water/fvec/Frame.java

+3
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,9 @@ else if (ocols instanceof Frame) {
817817
else if (orows instanceof long[]) {
818818
final long CHK_ROWS=1000000;
819819
long[] rows = (long[])orows;
820+
if (this.numRows() == 0) {
821+
return this;
822+
}
820823
if( rows.length==0 || rows[0] < 0 ) {
821824
if (rows[0] < 0) {
822825
Vec v = (new SelectVec(rows)).doAll(this.anyVec().makeZero()).getResult()._fr.anyVec();

0 commit comments

Comments
 (0)