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 type coercion in bmerge #6603

Merged
merged 44 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e04e67f
fix type coercion in bmerge
ben-schwen Nov 3, 2024
c55bfcc
fix bracket
ben-schwen Nov 3, 2024
272fc59
add test cases
ben-schwen Nov 3, 2024
3aba1cc
fix lint
ben-schwen Nov 3, 2024
1d7a8c2
fix old test case
ben-schwen Nov 3, 2024
ff934cc
rename x/i class
ben-schwen Nov 24, 2024
a75fb0e
add minimal test
ben-schwen Nov 24, 2024
1bb60bf
indent loop
ben-schwen Nov 24, 2024
7ee12aa
add fix in one direction
ben-schwen Nov 24, 2024
562a9fd
remove indent to cater for diff
ben-schwen Nov 26, 2024
49f849b
Revert "remove indent to cater for diff"
ben-schwen Nov 26, 2024
cfa5d71
remove indent
ben-schwen Nov 26, 2024
6b8f11f
add 2nd case
ben-schwen Nov 26, 2024
a651b03
remove trailing ws
ben-schwen Nov 26, 2024
839463e
update all cases
ben-schwen Nov 26, 2024
935ac60
fix typo
ben-schwen Nov 26, 2024
f1997e0
fix test cases
ben-schwen Nov 26, 2024
25eaa65
update testcases
ben-schwen Nov 26, 2024
f0219c4
update copying attributes from int to dbl
ben-schwen Nov 26, 2024
ca6756f
start modularize
ben-schwen Nov 27, 2024
d41bbf2
fix cases
ben-schwen Nov 27, 2024
33d7009
ensure same types for test
ben-schwen Nov 27, 2024
91c53c5
add test for codecov
ben-schwen Nov 27, 2024
6c68fb7
simplify
ben-schwen Nov 27, 2024
5aaee92
fix test on windows
ben-schwen Nov 27, 2024
7a64f22
simplify
ben-schwen Nov 27, 2024
69a7b20
add coerce function
ben-schwen Nov 27, 2024
3023b5c
modularize more
ben-schwen Nov 27, 2024
4dfe8ab
Use gettext() on character strings directly
MichaelChirico Nov 27, 2024
faa5474
rename getClass helper: mergeType
MichaelChirico Nov 27, 2024
56e3169
rename: {i,x}c --> {i,x}col
MichaelChirico Nov 27, 2024
8deaa6a
comment ref. issue
MichaelChirico Nov 27, 2024
81b3657
exchange subset with .shallow
ben-schwen Nov 30, 2024
c9d3d74
undo test
ben-schwen Nov 30, 2024
e171500
Revert "undo test"
ben-schwen Nov 30, 2024
7195697
update tests
ben-schwen Nov 30, 2024
6143ef7
add comment
ben-schwen Nov 30, 2024
637ff58
add non right join testcase
ben-schwen Nov 30, 2024
03968e8
move helper outside bmerge
ben-schwen Nov 30, 2024
7e7c1c6
update comment
ben-schwen Nov 30, 2024
efc21c3
add NEWS
ben-schwen Nov 30, 2024
23f8e6d
Merge branch 'master' into bmerge_coercion
ben-schwen Nov 30, 2024
ba03d5e
update numbering
ben-schwen Nov 30, 2024
f5fb825
tweak NEWS
MichaelChirico Dec 2, 2024
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
8 changes: 7 additions & 1 deletion R/bmerge.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
stopf("Incompatible join types: %s (%s) and %s (%s). Factor columns must join to factor or character columns.", xname, xclass, iname, iclass)
}
if (xclass == iclass) {
ben-schwen marked this conversation as resolved.
Show resolved Hide resolved
if (verbose) catf("%s has same type (%s) as %s. No coercion needed.\n", iname, xclass, xname)
if (length(icols)>1 && is(x[[xc]], "Date") && is(i[[ic]], "Date")) {
ben-schwen marked this conversation as resolved.
Show resolved Hide resolved
set(x, j=xc, value=as.double(x[[xc]]))
set(i, j=ic, value=as.double(i[[ic]]))
if (verbose) catf("%s and %s are both Dates. R does not guarentee a type for Date internally, hence, coercing to double.\n", iname, xname)
} else {
if (verbose) catf("%s has same type (%s) as %s. No coercion needed.\n", iname, xclass, xname)
}
next
}
if (xclass=="character" || iclass=="character" ||
Expand Down
12 changes: 11 additions & 1 deletion inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -15727,7 +15727,8 @@ DT = data.table(z = 1i)
test(2069.33, DT[DT, on = 'z'], error = "Type 'complex' is not supported for joining/merging")

# forder verbose message when !isReallyReal Date, #1738
DT = data.table(d=sample(seq(as.Date("2015-01-01"), as.Date("2015-01-05"), by="days"), 20, replace=TRUE))
date_dbl = as.Date(as.double(seq(as.Date("2015-01-01"), as.Date("2015-01-05"), by="days")), origin="1970-01-01")
ben-schwen marked this conversation as resolved.
Show resolved Hide resolved
DT = data.table(d=sample(date_dbl, 20, replace=TRUE))
test(2070.01, typeof(DT$d), "double")
test(2070.02, DT[, .N, keyby=d, verbose=TRUE], output="Column 1.*date.*8 byte double.*no fractions are present.*4 byte integer.*to save space and time")

Expand Down Expand Up @@ -20596,3 +20597,12 @@ test(2295.3, is.data.table(d2))

# #6588: .checkTypos used to give arbitrary strings to stopf as the first argument
test(2296, d2[x %no such operator% 1], error = '%no such operator%')

# coerce Dates to double if join on multiple columns, #6602
date_int = seq(as.Date('2015-01-01'), as.Date('2015-01-01'), by="day")
date_dbl = as.Date('2015-01-01')
x = data.table(a=date_int, b=1L)
ben-schwen marked this conversation as resolved.
Show resolved Hide resolved
y = data.table(c=date_int, d=date_dbl)

test(2297.1, options=c(datatable.verbose=TRUE), y[x, on=.(c == a)], data.table(c=date_int, d=date_dbl, b=1L), output="No coercion needed.")
test(2297.2, options=c(datatable.verbose=TRUE), y[x, on=.(c == a, d == a)], data.table(c=date_int, d=date_int, b=1L), output="coercing to double.")
ben-schwen marked this conversation as resolved.
Show resolved Hide resolved
Loading