Skip to content

Added format specifier for yearqtr#7713

Open
LunaticSage218 wants to merge 7 commits intoRdatatable:masterfrom
LunaticSage218:master
Open

Added format specifier for yearqtr#7713
LunaticSage218 wants to merge 7 commits intoRdatatable:masterfrom
LunaticSage218:master

Conversation

@LunaticSage218
Copy link
Copy Markdown

@LunaticSage218 LunaticSage218 commented Apr 21, 2026

Towards #7694

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.04%. Comparing base (8364344) to head (9e75f46).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7713      +/-   ##
==========================================
- Coverage   99.04%   99.04%   -0.01%     
==========================================
  Files          87       87              
  Lines       17037    17138     +101     
==========================================
+ Hits        16874    16974     +100     
- Misses        163      164       +1     

☔ 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 man/IDateTime.Rd Outdated
Co-authored-by: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com>
Comment thread R/IDateTime.R Outdated
Comment thread NEWS.md Outdated
@ben-schwen
Copy link
Copy Markdown
Member

Solid first approach. Keep in mind that we strive for efficiency with data.table so before calculating smth twice in a short period, we most of the time cache it.

Comment thread inst/tests/tests.Rraw Outdated
test(2368.3, yearqtr(x, format="character"), c("1111Q4", "2019Q1", "2019Q1", "2019Q1", "2019Q4", "2020Q1", "2020Q1", "2020Q4", "2040Q1", "2040Q4", "2100Q1", NA_character_))
test(2368.4, yearqtr("2016-08-03 01:02:03.45", format="character"), "2016Q3")
test(2368.5, yearqtr(NA, format="character"), NA_character_)
test(2368.6, yearqtr(x, format="invalid"), error="should be one of")
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.

Pls delete test case 6, since you are essentially testing for the R error message of match.arg, which is beyond our control

Comment thread man/IDateTime.Rd
yearmon(x)
yearqtr(x)

yearqtr(x, format = c("numeric", "character"))
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.

Suggested change
yearqtr(x, format = c("numeric", "character"))
yearqtr(x, format = c("numeric", "character"))

reinstate deletion of missing line

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.

We are close to being mergeable.

However, to fully close the issue you would also need to mirror the approach for yearmon with a similar encoding d="2019-01-01" as yearmon(d, "character") as "2019M1"

Comment thread R/IDateTime.R Outdated
if (format == "numeric") return(yqtr)
yr = floor(yqtr)
qtr = round((yqtr - yr) * 4) + 1L
ans = paste0(yr, "Q", qtr)
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 go with allocating NA vector first, and then filling up non-NA, less input to paste, which needs to populate global string cache on each string.

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.

3 participants