Skip to content

Commit ccd481f

Browse files
add test and appropriate changes
1 parent 56d696d commit ccd481f

File tree

3 files changed

+16
-24
lines changed

3 files changed

+16
-24
lines changed

R/bmerge.R

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,17 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
8484
next
8585
}
8686
}
87-
condition_message <- sprintf(
88-
"Incompatible join types: %s (%s) and %s (%s). Factor columns must join to factor or character columns.", # Exact match for tests like 2044.24
89-
xname, x_merge_type,
90-
iname, i_merge_type
91-
)
92-
condition <- structure(
87+
condition_message = gettextf("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+
condition = structure(
9389
list(
9490
message = condition_message,
91+
call = sys.call(sys.nframe()-1L),
9592
bmerge_x_arg_col_name = names(x)[xcol],
9693
bmerge_x_arg_type = x_merge_type,
9794
bmerge_i_arg_col_name = names(i)[icol],
9895
bmerge_i_arg_type = i_merge_type
9996
),
100-
class = c("bmerge_incompatible_type_error", "data.table_error", "error", "condition")
97+
class = c("dt_bmerge_incompatible_type_error", "error", "condition")
10198
)
10299
stop(condition)
103100
}

R/merge.R

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,16 @@ merge.data.table = function(x, y, by = NULL, by.x = NULL, by.y = NULL, all = FAL
9797
y = y[yind]
9898
}
9999

100-
dt <- tryCatch({
100+
dt = tryCatch({
101101
y[x, nomatch=if (all.x) NA else NULL, on=by, allow.cartesian=allow.cartesian]
102102
},
103-
bmerge_incompatible_type_error = function(e) {
104-
# For merge(x=DT1, y=DT2), DT1 (user's 'x') is bmerge's 'i'
105-
# DT2 (user's 'y') is bmerge's 'x'
106-
x_part_col_name <- e$bmerge_i_arg_col_name
107-
x_part_type <- e$bmerge_i_arg_type
108-
y_part_col_name <- e$bmerge_x_arg_col_name
109-
y_part_type <- e$bmerge_x_arg_type
103+
dt_bmerge_incompatible_type_error = function(e) {
104+
x_part_col_name = e$bmerge_i_arg_col_name
105+
x_part_type = e$bmerge_i_arg_type
106+
y_part_col_name = e$bmerge_x_arg_col_name
107+
y_part_type = e$bmerge_x_arg_type
110108

111-
# Use literal "x." and "y." prefixes referring to the arguments of merge()
112-
msg <- sprintf(
113-
"Incompatible join types: x.%s (%s) and i.%s (%s). Factor columns must join to factor or character columns.",
114-
x_part_col_name, x_part_type,
115-
y_part_col_name, y_part_type
116-
)
117-
118-
# Remove call = NULL to get "Error in merge.data.table(...): " prefix.
119-
stop(errorCondition(message = msg, class = c("datatable_merge_type_error", "data.table_error", "error", "condition")))
109+
stopf("Incompatible join types: x.%s (%s) and i.%s (%s). Factor columns must join to factor or character columns.", x_part_col_name, x_part_type, y_part_col_name, y_part_type, class = "dt_merge_incompatible_type_error")
120110
}
121111
)
122112

inst/tests/tests.Rraw

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21157,3 +21157,8 @@ test(2317.6, DT1[DF1, on='a', .(d = x.a + i.d)]$d, 5)
2115721157
test(2317.7, DT1[DF2, on='a', e := i.e]$e, 5)
2115821158
test(2317.8, DT1[DF2, on='a', e2 := x.a + i.e]$e2, 6)
2115921159
test(2317.9, DT1[DF2, on='a', .(e = x.a + i.e)]$e, 6)
21160+
21161+
# Test for incompatible factor joins rephrased by merge.data.table(#7048)
21162+
DT1=data.table(a=factor('a'))
21163+
DT2=data.table(a=1L)
21164+
test(2318, merge(DT1, DT2, by = "a"), error = "Incompatible join types: x.a (factor) and i.a (integer). Factor columns must join to factor or character columns.")

0 commit comments

Comments
 (0)