-
Notifications
You must be signed in to change notification settings - Fork 997
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skip sorting already sorted #4501
Changes from 4 commits
7463633
ac5561d
934b1dc
d1662b3
21e68c0
4b6ea43
83ff6c1
2d97ae0
d4c3a6b
739abe5
353dc7a
245a800
23ec54f
45125ad
1b5f5a1
6bb0642
92a0711
b594be7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1336,9 +1336,25 @@ replace_dot_alias = function(e) { | |
|
||
if (is.data.table(jval)) { | ||
setattr(jval, 'class', class(x)) # fix for #64 | ||
if (haskey(x) && all(key(x) %chin% names(jval)) && suppressWarnings(is.sorted(jval, by=key(x)))) # TO DO: perhaps this usage of is.sorted should be allowed internally then (tidy up and make efficient) | ||
# can jval be sorted by the same key as x? improved for #4498 | ||
get_shared_keys = function(jsub, jvnames, key) { | ||
if (is.null(key)) return(NULL) | ||
if (!jsub %iscall% "list") return(NULL) | ||
jnames = as.character(Filter(is.name, jsub)[-1L]) | ||
key_idx = chmatch(key, jnames) | ||
missing_keys = which(is.na(key_idx)) | ||
if (length(missing_keys) && missing_keys[1L] == 1L) return(NULL) | ||
if (!length(missing_keys)) return(jvnames[key_idx]) | ||
return(jvnames[head(key_idx, missing_keys[1L] - 1L)]) | ||
} | ||
shared_keys = get_shared_keys(jsub, jvnames, key(x)) | ||
if (is.null(irows) && !is.null(shared_keys)) { | ||
setattr(jval, 'sorted', shared_keys) | ||
# potentially inefficient backup -- check if jval is sorted by key(x) | ||
} else if (haskey(x) && all(key(x) %chin% names(jval)) && suppressWarnings(is.sorted(jval, by=key(x)))) { # TO DO: perhaps this usage of is.sorted should be allowed internally then (tidy up and make efficient) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have dropped this branch but there are a few tests relying on it, e.g. when Do we check anywhere else whether @ColeMiller1 please have a look, I think the logic is improved but maybe could be further. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this above:
but only in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like your new fx. We may want to check for I think the
I can work on it some this evening. |
||
setattr(jval, 'sorted', key(x)) | ||
if (any(sapply(jval, is.null))) stop("Internal error: j has created a data.table result containing a NULL column") # nocov | ||
} | ||
if (any(vapply_1b(jval, is.null))) stop("Internal error: j has created a data.table result containing a NULL column") # nocov | ||
} | ||
return(jval) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3641,7 +3641,7 @@ test(1118, dt[, lapply(.SD, function(y) weighted.mean(y, b2, na.rm=TRUE)), by=x] | |
|
||
# a(nother) test of #295 | ||
DT <- data.table(x=5:1, y=1:5, key="y") | ||
test(1119, is.null(key(DT[, list(z = y, y = 1/y)]))) | ||
test(1119, key(DT[, list(z = y, y = 1/y)]), 'z') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. before (as in, the reason for this test), I think |
||
|
||
## various ordered factor rbind tests | ||
DT1 = data.table(ordered('a', levels = c('a','b','c'))) | ||
|
@@ -16861,3 +16861,10 @@ A = data.table(A=c(complex(real = 1:3, imaginary=c(0, -1, 1)), NaN)) | |
test(2138.3, rbind(A,B), data.table(A=c(as.character(A$A), B$A))) | ||
A = data.table(A=as.complex(rep(NA, 5))) | ||
test(2138.4, rbind(A,B), data.table(A=c(as.character(A$A), B$A))) | ||
|
||
# sub-key can also be retained in plain query, part of #4498 | ||
DT = data.table(id = rep(1:10, 2L), grp = rep(1:2, each=10L), V = 1:20/13, key=c('id', 'grp')) | ||
test(2139.1, key(DT[ , .(id)]), 'id') | ||
test(2139.2, key(DT[ , .(grp)]), NULL) | ||
## renaming also caught | ||
test(2139.3, key(DT[ , .(newid = id, newgrp = grp)]), c('newid', 'newgrp')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to link user via
@
because it could eventually point to a different user here on githubThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pinged them on SO to add their name if possible. will leave this for now