From f60d75b28fb318b4be41b9fe751da1aae59cb247 Mon Sep 17 00:00:00 2001 From: Bill Evans Date: Sun, 10 Nov 2024 13:54:11 -0500 Subject: [PATCH 1/2] close #6605, joins on date/time do not warn --- NEWS.md | 2 ++ R/bmerge.R | 8 ++++++++ inst/tests/tests.Rraw | 3 +++ 3 files changed, 13 insertions(+) diff --git a/NEWS.md b/NEWS.md index 4236e8b078..1a50ca0968 100644 --- a/NEWS.md +++ b/NEWS.md @@ -115,6 +115,8 @@ rowwiseDT( 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. +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. + ## 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. diff --git a/R/bmerge.R b/R/bmerge.R index aa7ea41039..c5f9a3f346 100644 --- a/R/bmerge.R +++ b/R/bmerge.R @@ -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 diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index d68130255b..8636d764f3 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -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") From b8c8f42a1107fb88e7392c9085fa0e5b37c3e404 Mon Sep 17 00:00:00 2001 From: Bill Evans Date: Thu, 14 Nov 2024 18:07:24 -0500 Subject: [PATCH 2/2] tweaks --- DESCRIPTION | 3 ++- NEWS.md | 2 +- inst/tests/tests.Rraw | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 25a7bd6d37..f94ee86669 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -98,5 +98,6 @@ Authors@R: c( person("Christian", "Wia", role="ctb"), person("Elise", "Maigné", role="ctb"), person("Vincent", "Rocher", role="ctb"), - person("Vijay", "Lulla", role="ctb") + person("Vijay", "Lulla", role="ctb"), + person("Bill", "Evans", role="ctb") ) diff --git a/NEWS.md b/NEWS.md index 004cbcd9c0..3bac65b779 100644 --- a/NEWS.md +++ b/NEWS.md @@ -107,7 +107,7 @@ 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. +12. 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. ## NOTES diff --git a/inst/tests/tests.Rraw b/inst/tests/tests.Rraw index 56530f2c7f..b8a1c248c7 100644 --- a/inst/tests/tests.Rraw +++ b/inst/tests/tests.Rraw @@ -20598,4 +20598,4 @@ test(2295.3, is.data.table(d2)) 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") +test(2297.1, data.table(a = .POSIXct(20000L), v1 = 1)[data.table(a = .Date(20000L), v2 = 2), on = "a"], output = ".+", warning = "incompatible")