diff --git a/inst/unitTests/runit.na.locf.R b/inst/unitTests/runit.na.locf.R index 42eca17d..37723980 100644 --- a/inst/unitTests/runit.na.locf.R +++ b/inst/unitTests/runit.na.locf.R @@ -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) + } +} diff --git a/src/na.c b/src/na.c index 4e4fcea5..28346917 100644 --- a/src/na.c +++ b/src/na.c @@ -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)) {