You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Check roll-on-factor up-front to simplify later checks (#6639)
* small refactor of bmerge() to check roll-on-factor condition first
* restore factor checks as coming first
---------
Co-authored-by: Benjamin Schwendinger <[email protected]>
if (is.factor(x[[last_x_idx]]) || is.factor(i[[last_i_idx]]))
34
+
stopf("Attempting roll join on factor column when joining x.%s to i.%s. Only integer, double or character columns may be roll joined.", names(x)[last_x_idx], names(i)[last_i_idx])
35
+
}
36
+
30
37
callersi=i
31
38
i= shallow(i)
32
39
# Just before the call to bmerge() in [.data.table there is a shallow() copy of i to prevent coercions here
if (!x_merge_type %chin% supported) stopf("%s is type %s which is not supported by data.table join", xname, x_merge_type)
66
73
if (!i_merge_type %chin% supported) stopf("%s is type %s which is not supported by data.table join", iname, i_merge_type)
74
+
# we check factors first because they might have different levels
67
75
if (x_merge_type=="factor"||i_merge_type=="factor") {
68
-
if (roll!=0.0&&a==length(icols))
69
-
stopf("Attempting roll join on factor column when joining %s to %s. Only integer, double or character columns may be roll joined.", xname, iname)
70
76
if (x_merge_type=="factor"&&i_merge_type=="factor") {
71
77
if (verbose) catf("Matching %s factor levels to %s factor levels.\n", iname, xname)
72
78
set(i, j=icol, value=chmatch(levels(i[[icol]]), levels(x[[xcol]]), nomatch=0L)[i[[icol]]]) # nomatch=0L otherwise a level that is missing would match to NA values
stopf("Incompatible join types: %s (%s) and %s (%s). Factor columns must join to factor or character columns.", xname, x_merge_type, iname, i_merge_type)
88
94
}
89
-
# we check factors first to cater for the case when trying to do rolling joins on factors
90
95
if (x_merge_type==i_merge_type) {
91
96
if (verbose) catf("%s has same type (%s) as %s. No coercion needed.\n", iname, x_merge_type, xname)
0 commit comments