Skip to content

Add limit parameter to nafill and setnafill #7677#7819

Open
venom1204 wants to merge 5 commits into
masterfrom
issue777666777
Open

Add limit parameter to nafill and setnafill #7677#7819
venom1204 wants to merge 5 commits into
masterfrom
issue777666777

Conversation

@venom1204

Copy link
Copy Markdown
Contributor

closes #7677

this PR adds a limit argument to nafill and setnafill to restrict the maximum number of consecutive NA values filled. Default is Inf to preserve existing behavior. Updated R interface, C kernel logic, and documentation.

hi @tdhock @joshhwuu can you please have a look at this when you got time thanks .

@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.64706% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.99%. Comparing base (895067d) to head (7c59afe).

Files with missing lines Patch % Lines
src/nafill.c 91.93% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7819      +/-   ##
==========================================
- Coverage   99.02%   98.99%   -0.03%     
==========================================
  Files          88       88              
  Lines       17266    17318      +52     
==========================================
+ Hits        17097    17144      +47     
- Misses        169      174       +5     

☔ 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 18, 2026

Copy link
Copy Markdown
  • HEAD=issue777666777 much slower for transform improved in #5493
  • HEAD=issue777666777 much slower for isoweek improved in #7144
    Comparison Plot

Generated via commit 7c59afe

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

Task Duration
R setup and installing dependencies 2 minutes and 33 seconds
Installing different package versions 22 seconds
Running and plotting the test cases 6 minutes and 40 seconds

Comment thread inst/tests/tests.Rraw Outdated
test(2379.01, nafill(c(1, NA, NA, NA, 5), type="locf", limit=1), c(1, 1, NA, NA, 5))
test(2379.02, nafill(c(1, NA, NA, 5, NA, NA, NA, 9), type="locf", limit=2), c(1, 1, 1, 5, 5, 5, NA, 9))
test(2379.03, nafill(c(1, NA, NA, 4, NA), type="locf", limit=Inf), c(1, 1, 1, 4, 4))
test(2379.04, nafill(c(NA, NA, 3, NA, NA), type="locf", limit=1), c(NA, NA, 3, 3, NA))

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.

whats the difference between 01 and 04?

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.

can we also test edge cases like negative, 0, NA, NaN, NULL?

Comment thread man/nafill.Rd Outdated
# limit= restricts the number of consecutive fills
y = c(1, NA, NA, NA, 5)
nafill(y, "locf", limit=1) # Only fills the first NA
nafill(y, "locf", limit=2) # Fills the first two NAs

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.

I dont get the added value of the second line, maybe change it to Inf for showcasing filling all.

Comment thread R/shift.R Outdated
type = match.arg(type)
.Call(CnafillR, x, type, fill, nan_is_na(nan), FALSE, NULL)
if (!is.numeric(limit) || length(limit) != 1L || limit < 0)
stopf("limit must be a non-negative scalar numeric or Inf")

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.

unprecise since Inf is also non-negative

@ben-schwen ben-schwen left a comment

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.

What about type="const". What about fractions like limit=1.5?

Please add tests for the following cases:

  • nocb
  • limit: 0, NA, NaN, negative, fractional, complex, NULL, and length > 1
  • integer and character
  • setnafill() by-reference

NEWS is missing.

What nafill(c(NA, 1), "locf", fill=0, limit=0)

@venom1204
venom1204 force-pushed the issue777666777 branch 2 times, most recently from 67e1f87 to dd875ac Compare July 25, 2026 14:03
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.

Could a parameter maxfill be added to na.fill

2 participants