Skip to content

between supports Date/IDate with missing bounds#7751

Open
grcatlin wants to merge 1 commit into
Rdatatable:masterfrom
grcatlin:master
Open

between supports Date/IDate with missing bounds#7751
grcatlin wants to merge 1 commit into
Rdatatable:masterfrom
grcatlin:master

Conversation

@grcatlin
Copy link
Copy Markdown

Closes #7281

I believe this implementation matches @aitap's suggestion, where Date/IDates are passed to the C code directly. I tried to line up the character bound parsing with the existing implementation for POSIXct.

This is my first time contributing to data.table and I'd appreciate any feedback!

@grcatlin grcatlin requested a review from MichaelChirico as a code owner May 18, 2026 21:02
@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.04%. Comparing base (188dd7b) to head (8dfa781).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7751   +/-   ##
=======================================
  Coverage   99.04%   99.04%           
=======================================
  Files          87       87           
  Lines       17065    17071    +6     
=======================================
+ Hits        16902    16908    +6     
  Misses        163      163           

☔ View full report in Codecov by Sentry.
📢 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.

Comment thread inst/tests/tests.Rraw
# errors name the bound that failed coercion
x = as.Date("2020-01-01") + 0:4
test(2038.39, between(x, "not-a-date", "2020-01-04"), error="Date while 'lower' was not, coercion to Date failed")
test(2038.40, between(x, "2020-01-02", "not-a-date"), error="Date while 'upper' was not, coercion to Date failed")
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.

not sure we need both and 2038.39 and 2038.40

Comment thread inst/tests/tests.Rraw
Comment on lines +14691 to +14694
x = data.table(Date = as.Date("2020-01-01") + 0:5, Active = c(TRUE, FALSE, TRUE, FALSE, TRUE, FALSE))
x[Active == TRUE, InRange := c(TRUE, FALSE, TRUE)]
x[InRange == TRUE, c("RangeBegin", "RangeEnd") := list(Date - 1L, Date + 1L)]
x[InRange == FALSE, c("RangeBegin", "RangeEnd") := list(Date + 1L, Date + 2L)]
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 would rather build x with a single step, like e.g.

Suggested change
x = data.table(Date = as.Date("2020-01-01") + 0:5, Active = c(TRUE, FALSE, TRUE, FALSE, TRUE, FALSE))
x[Active == TRUE, InRange := c(TRUE, FALSE, TRUE)]
x[InRange == TRUE, c("RangeBegin", "RangeEnd") := list(Date - 1L, Date + 1L)]
x[InRange == FALSE, c("RangeBegin", "RangeEnd") := list(Date + 1L, Date + 2L)]
x = data.table(
Date = as.Date("2020-01-01") + 0:5,
Active = c(TRUE, FALSE, TRUE, FALSE, TRUE, FALSE),
InRange = c(TRUE, NA, FALSE, NA, TRUE, NA),
RangeBegin = as.Date("2020-01-01") + c(-1L, NA, 3L, NA, 3L, NA),
RangeEnd = as.Date("2020-01-01") + c( 1L, NA, 4L, NA, 5L, NA)
)

Comment thread inst/tests/tests.Rraw
x[InRange == FALSE, c("RangeBegin", "RangeEnd") := list(Date + 1L, Date + 2L)]
test(2038.36, x[Active == TRUE & between(Date, RangeBegin, RangeEnd), Date], as.Date(c("2020-01-01", "2020-01-05")))
# Date character bounds coercion
test(2038.37, between(x$Date, "2020-01-02", "2020-01-04"), c(FALSE, TRUE, TRUE, TRUE, 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.

This test does not fail pre the PR, so its probably covering the same lines (just food for thought)

Copy link
Copy Markdown
Member

@ben-schwen ben-schwen left a comment

Choose a reason for hiding this comment

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

code change LGTM. some minor things about the tests.

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.

Inconsistent between() behavior on dates due to NAbounds argument

2 participants