Skip to content

Commit

Permalink
Fix multi-column filling when first column all NA
Browse files Browse the repository at this point in the history
The firstNonNA check only checks the first column for a 2-dimensional
SEXP.  Therefore if the first column is NA, the function returns
without examining any other columns.

Fix by removing this check.

Fixes joshuaulrich#233
  • Loading branch information
TomAndrews committed Apr 18, 2018
1 parent 31b5911 commit ae31bda
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 14 additions & 0 deletions inst/unitTests/runit.na.locf.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,17 @@ test.nalocf_by_column_1NA_fromLast <- function() {
checkEquals(x, as.xts(z), check.attributes = TRUE)
}
}

test.nalocf_first_column_all_NA <- function() {
nacol <- 1L
for (m in MODES) {
xdat <- XDAT2
xdat[,nacol] <- xdat[,nacol] * NA
storage.mode(xdat) <- m
zdat <- as.zoo(xdat)

x <- na.locf(xdat)
z <- na.locf(zdat)
checkEquals(x, as.xts(z), check.attributes = TRUE)
}
}
3 changes: 0 additions & 3 deletions src/na.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ SEXP na_locf (SEXP x, SEXP fromLast, SEXP _maxgap, SEXP _limit)
limit = asReal(_limit);
gap = 0;

if(firstNonNA(x) == nr)
return(x);

PROTECT(result = allocMatrix(TYPEOF(x), nr, nc)); P++;

switch(TYPEOF(x)) {
Expand Down

0 comments on commit ae31bda

Please sign in to comment.