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

close #6605, joins on date/time do not warn #6610

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ rowwiseDT(

11. `tables()` now returns the correct size for data.tables over 2GiB, [#6607](https://github.com/Rdatatable/data.table/issues/6607). Thanks to @vlulla for the report and the PR.

16. Joining with incompatible column times (e.g., `Date` with `POSIXt`) now provides a clear warning, [#6605](https://github.com/Rdatatable/data.table/issues/6605). Thanks to @al-obrien for the report and @r2evans for the PR.
ben-schwen marked this conversation as resolved.
Show resolved Hide resolved

## NOTES

1. Tests run again when some Suggests packages are missing, [#6411](https://github.com/Rdatatable/data.table/issues/6411). Thanks @aadler for the note and @MichaelChirico for the fix.
Expand Down
8 changes: 8 additions & 0 deletions R/bmerge.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ 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)
}
# data.table::as.ITime, chron::times, nanotime::nanotime
timeclasses = c("Date", "POSIXt", "ITime", "times", "nanotime")
xclass_time = intersect(class(x[[xc]]), timeclasses)
iclass_time = intersect(class(i[[ic]]), timeclasses)
if (length(xclass_time) > 0L && length(iclass_time) > 0L && !identical(sort(xclass_time), sort(iclass_time))) {
warningf("Attempting to join column %s (%s) with column %s (%s). They are likely to be incompatible numbers, suggest you convert one to the other's class.",
xname, toString(xclass_time), iname, toString(iclass_time))
}
if (xclass == iclass) {
if (verbose) catf("%s has same type (%s) as %s. No coercion needed.\n", iname, xclass, xname)
next
Expand Down
3 changes: 3 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -20596,3 +20596,6 @@ 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%')

# #6605: Joins do not warn user when using POSc and Date comparisons
test(2297.1, data.table(a = Sys.time(), v1 = 1)[data.table(a = Sys.Date(), v2 = 2), on = "a"], output = ".+", warning = "incompatible")
ben-schwen marked this conversation as resolved.
Show resolved Hide resolved
Loading