Skip to content

Commit f60d75b

Browse files
committed
close #6605, joins on date/time do not warn
1 parent afa87e1 commit f60d75b

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ rowwiseDT(
115115
116116
15. `DT[1, on=NULL]` now works for returning the first row, [#6579](https://github.com/Rdatatable/data.table/issues/6579). Thanks to @Kodiologist for the report and @tdhock for the PR.
117117
118+
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.
119+
118120
## NOTES
119121
120122
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.

R/bmerge.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ bmerge = function(i, x, icols, xcols, roll, rollends, nomatch, mult, ops, verbos
7070
}
7171
stopf("Incompatible join types: %s (%s) and %s (%s). Factor columns must join to factor or character columns.", xname, xclass, iname, iclass)
7272
}
73+
# data.table::as.ITime, chron::times, nanotime::nanotime
74+
timeclasses = c("Date", "POSIXt", "ITime", "times", "nanotime")
75+
xclass_time = intersect(class(x[[xc]]), timeclasses)
76+
iclass_time = intersect(class(i[[ic]]), timeclasses)
77+
if (length(xclass_time) > 0L && length(iclass_time) > 0L && !identical(sort(xclass_time), sort(iclass_time))) {
78+
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.",
79+
xname, toString(xclass_time), iname, toString(iclass_time))
80+
}
7381
if (xclass == iclass) {
7482
if (verbose) catf("%s has same type (%s) as %s. No coercion needed.\n", iname, xclass, xname)
7583
next

inst/tests/tests.Rraw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20596,3 +20596,6 @@ test(2295.3, is.data.table(d2))
2059620596

2059720597
# #6588: .checkTypos used to give arbitrary strings to stopf as the first argument
2059820598
test(2296, d2[x %no such operator% 1], error = '%no such operator%')
20599+
20600+
# #6605: Joins do not warn user when using POSc and Date comparisons
20601+
test(2297.1, data.table(a = Sys.time(), v1 = 1)[data.table(a = Sys.Date(), v2 = 2), on = "a"], output = ".+", warning = "incompatible")

0 commit comments

Comments
 (0)