Skip to content

as.IDate() : floor fractional dates, #7952 - #7966

Merged
ben-schwen merged 7 commits into
Rdatatable:masterfrom
simplymayank:7952-fix-fractional-dates
Dec 5, 2026
Merged

ben-schwen merged 7 commits into
Rdatatable:masterfrom
simplymayank:7952-fix-fractional-dates

Conversation

@simplymayank

Copy link
Copy Markdown
Contributor

Closes #7952

as.IDate() truncated fractional Date and numeric inputs toward zero, so negative fractions (e.g. -0.5) gave the wrong day. This now floors instead.

The approach follows the fix suggested by @ben-schwen in @ben-schwen's comment.

Changes

  • Add floor_to_int() to handle fractional Date and numeric inputs.
  • Add tests for fractional Date and numeric inputs around the Unix epoch.
  • Add NEWS entry.

Testing

  • I checked that the new negative-value tests fail on current master and pass with this change.
  • test.data.table() passes and R CMD check completes with no errors, warnings, or notes

Performance

Used bench::mark() for floor_to_int() against the previous as.integer() on 1 million values:

  • Random double values: median 2.4 ms -> 11.6 ms.
  • Integer-valued doubles: median 2.34 ms -> 6.68 ms.
  • Integer vectors: 400 ns -> 4 µs.

This change ensures correct date conversion for negative fractional values, with some additional processing time for double inputs.

@codecov

codecov Bot commented Dec 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.87%. Comparing base (e85342d) to head (b6295f0).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7966   +/-   ##
=======================================
  Coverage   96.86%   96.87%           
=======================================
  Files          87       87           
  Lines       17476    17478    +2     
=======================================
+ Hits        16929    16931    +2     
  Misses        547      547           

☔ 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.

@ben-schwen
ben-schwen merged commit 3915586 into Rdatatable:master Dec 5, 2026
12 checks passed
@ben-schwen

Copy link
Copy Markdown
Member

TY!

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.

Document as.IDate() behaviour with fractional dates

2 participants