Skip to content

Commit 16c6fdc

Browse files
Account for roll='nearest' when checking result key (#7148)
* Account for roll='nearest' * roll==0 is the same as !roll, so isFALSE won't do
1 parent 1ebc819 commit 16c6fdc

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
8888
8. A data.table with a column of class `vctrs_list_of` (from package {vctrs}) prints as expected, [#5948](https://github.com/Rdatatable/data.table/issues/5948). Before, they could be printed messily, e.g. printing every entry in a nested data.frame. Thanks @jesse-smith for the report, @DavisVaughan and @r2evans for contributing, and @MichaelChirico for the PR.
8989
90-
9. Fixed incorrect sorting of merges where the first column of a key is a factor with non-`sort()`-ed levels (e.g. `factor(1:2, 2:1)` and it is joined to a character column, [#5361](https://github.com/Rdatatable/data.table/issues/5361). Thanks to @gbrunick for the report and Benjamin Schwendinger for the fix.
90+
9. Fixed incorrect sorting of merges where the first column of a key is a factor with non-`sort()`-ed levels (e.g. `factor(1:2, 2:1)` and it is joined to a character column, [#5361](https://github.com/Rdatatable/data.table/issues/5361). Thanks to @gbrunick for the report, Benjamin Schwendinger for the fix, and @MichaelChirico for a follow-up fix caught by revdep testing.
9191
9292
10. Spurious warnings from internal code in `cube()`, `rollup()`, and `groupingsets()` are no longer surfaced to the caller, [#6964](https://github.com/Rdatatable/data.table/issues/6964). Thanks @ferenci-tamas for the report and @venom1204 for the fix.
9393

R/data.table.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,8 +2047,9 @@ replace_dot_alias = function(e) {
20472047
if (!.Call(CisOrderedSubset, irows, nrow(x)))
20482048
return(NULL)
20492049

2050-
# see #1010. don't set key when i has no key, but irows is ordered and !roll
2051-
if (roll && length(irows) != 1L)
2050+
# see #1010. don't set key when i has no key, but irows is ordered and isFALSE(roll)
2051+
# NB: roll could still be a string like 'nearest', #7146
2052+
if (!is.character(roll) && roll && length(irows) != 1L)
20522053
return(NULL)
20532054

20542055
new_key <- head(x_key, key_length)

inst/tests/tests.Rraw

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7131,6 +7131,11 @@ dt3 <- merge(dt1, dt2, by="x")
71317131
test(1483.81, key(dt3), "x")
71327132
test(1483.82, nrow(dt3[x %in% "c", ]), 2L)
71337133

7134+
# avoid regression of roll='nearest' join of int->double, #7146
7135+
DT1 <- data.table(a=1L, key='a')
7136+
DT2 <- data.table(a=2.0, key='a')
7137+
test(1483.83, DT1[DT2, roll='nearest'], data.table(a=2L, key='a'))
7138+
71347139
# NULL items should be removed when making data.table from list, #842
71357140
# Original fix for #842 added a branch in as.data.table.list() using point()
71367141
# Then PR#3471 moved logic from data.table() into as.data.table.list() and now removes NULL items up front, so longer need for the branch

0 commit comments

Comments
 (0)