Skip to content

Allow setnafill() to accept logical vectors in cols (#4113) - #7842

Open
venom1204 wants to merge 6 commits into
masterfrom
issue41113
Open

Allow setnafill() to accept logical vectors in cols (#4113)#7842
venom1204 wants to merge 6 commits into
masterfrom
issue41113

Conversation

@venom1204

Copy link
Copy Markdown
Contributor

CLOSES #4113

this PR enables setnafill() to accept logical vectors for the cols argument, allowing for dynamic column selection via conditions like sapply(DT, is.numeric). The implementation updates the internal colnamesInt C utility to handle logical vectors with exact length matching and NA validation while ensuring that existing error-handling logic remains consistent across the package.

@codecov

codecov Bot commented Jul 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.01%. Comparing base (accac97) to head (986c878).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7842      +/-   ##
==========================================
- Coverage   99.01%   99.01%   -0.01%     
==========================================
  Files          88       88              
  Lines       17288    17293       +5     
==========================================
+ Hits        17118    17122       +4     
- Misses        170      171       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Jul 26, 2026

Copy link
Copy Markdown
  • HEAD=issue41113 much slower for transform improved in #5493
  • HEAD=issue41113 much slower for fread disk overhead improved in #6925
  • HEAD=issue41113 faster P<0.001 for memrecycle regression fixed in #5463
  • HEAD=issue41113 faster P<0.001 for DT[by,verbose=TRUE] improved in #6296
    Comparison Plot

Generated via commit 986c878

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 2 minutes and 51 seconds
Installing different package versions 1 minutes and 10 seconds
Running and plotting the test cases 5 minutes and 35 seconds

@venom1204 venom1204 changed the title UPDATED CHANGES Allow setnafill() to accept logical vectors in cols (#4113) Jul 26, 2026
Comment thread R/shift.R Outdated
Comment on lines +36 to +37
if (!is.list(x)) stop("in-place update is supported only for list", call. = FALSE)
cols = .Call(CcolnamesInt, x, cols, FALSE, FALSE)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling colnamesInt here seems the wrong approach to me, since we also call it in nafillR. Something simple as without additional C logic

if (is.logical(cols)) {
  if (length(cols) != length(x)) stopf("'cols' is a logical vector of length %d but there are %d columns", length(cols), length(x))
  if (anyNA(cols)) stopf("'cols' contains NA at position %d", which(is.na(cols))[1L])
  cols = which(cols)
}

Comment thread inst/tests/tests.Rraw
rm(inner, DT, DT2)

# #4113 setnafill could accept cols=logical(ncol(x))
test(2382.01, {DT = data.table(a=c(1,NA,3), b=c(4,NA,6), c=c(7,NA,9)); DT1 = copy(DT); DT2 = copy(DT); setnafill(DT1, type="locf", cols=c(TRUE,FALSE,TRUE)); setnafill(DT2, type="locf", cols=c(1L,3L)); identical(DT1, DT2)}, TRUE)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rather use a setup step, then trying to do everything in one step.
Also, most of the time we test against fixed values. If you really want to test integer indices versus logical indexing, I would suggest

Suggested change
test(2382.01, {DT = data.table(a=c(1,NA,3), b=c(4,NA,6), c=c(7,NA,9)); DT1 = copy(DT); DT2 = copy(DT); setnafill(DT1, type="locf", cols=c(TRUE,FALSE,TRUE)); setnafill(DT2, type="locf", cols=c(1L,3L)); identical(DT1, DT2)}, TRUE)
DT = data.table(a=c(1,NA,3), b=c(4,NA,6), c=c(7,NA,9))
test(2382.01, setnafill(copy(DT), type="locf", cols=c(TRUE,FALSE,TRUE)), setnafill(copy(DT), type="locf", cols=c(1L,3L)))

Comment thread R/shift.R

setnafill = function(x, type=c("const","locf","nocb"), fill=NA, nan=NA, cols=seq_along(x)) {
type = match.arg(type)
if (!is.list(x)) stop("in-place update is supported only for list", call. = FALSE)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this line?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setnafill could accept cols=logical(ncol(x))

2 participants