Skip to content
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

Fix handling of complex data types in data.table joins #6664

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions R/bmerge.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

mergeType = function(x) {
ans = typeof(x)
if (ans=="integer") { if (is.factor(x)) ans = "factor" }

Check warning on line 5 in R/bmerge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/bmerge.R,line=5,col=3,[if_switch_linter] Prefer switch() statements over repeated if/else equality tests, e.g., switch(x, a = 1, b = 2) over if (x == "a") 1 else if (x == "b") 2.
else if (ans=="double") { if (inherits(x, "integer64")) ans = "integer64" }
else if (ans == "complex") { if (all(Im(x) == 0)) ans = "double"

Check warning on line 7 in R/bmerge.R

View workflow job for this annotation

GitHub Actions / lint-r

file=R/bmerge.R,line=7,col=74,[trailing_whitespace_linter] Remove trailing whitespace.
else ans = "invalid" }
# do not call fitsInInt*(x) yet because i) if both types are double we don't need to coerce even if one or both sides
# are int-as-double, and ii) to save calling it until we really need it
ans
Expand Down Expand Up @@ -108,9 +110,13 @@
set(w, j=wc, value=bit64::as.integer64(w[[wc]]))
} else stopf("Incompatible join types: %s is type integer64 but %s is type double and cannot be coerced to integer64 (e.g. has fractions)", nm[2L], nm[1L])
} else {
# just integer and double left
# integer, double, and complex types remaining; complex treated as double if Im(x) == 0, otherwise invalid
ic_idx = which(icol == icols) # check if on is joined on multiple conditions, #6602
if (i_merge_type=="double") {
if (x_merge_type == "complex" || i_merge_type == "complex") {
if (x_merge_type == "invalid" || i_merge_type == "invalid") {
stopf("Incompatible join types: %s (%s) and %s (%s). Complex columns with non-zero imaginary parts are not supported.", xname, x_merge_type, iname, i_merge_type)
}
} else if (i_merge_type=="double") {
coerce_x = FALSE
if (fitsInInt32(i[[icol]])) {
coerce_x = TRUE
Expand Down
Loading