Skip to content

Commit 35b834e

Browse files
author
Michael Chirico
committed
Closes #2068 -- improve strptime wrapper warning message
1 parent a8e926a commit 35b834e

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@
266266
267267
15. `first` and `last` gain an explicit `n=1L` argument so that it's clear the default is 1, and their almost identical manual pages have been merged into one.
268268

269+
16. Re-wrote the warning about `strptime` usage in `j` to be more helpful/informative/actionable, [#2068](https://github.com/Rdatatable/data.table/issues/2068). Thanks to @tdhock for the report.
270+
269271

270272
### Changes in [v1.12.2](https://github.com/Rdatatable/data.table/milestone/14?closed=1) (07 Apr 2019)
271273

R/data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ replace_order = function(isub, verbose, env) {
11491149
SDenv = new.env(parent=parent.frame())
11501150
# taking care of warnings for posixlt type, #646
11511151
SDenv$strptime = function(x, ...) {
1152-
warning("POSIXlt column type detected and converted to POSIXct. We do not recommend use of POSIXlt at all because it uses 40 bytes to store one date. Use as.POSIXct to avoid this warning.")
1152+
warning("strptime() usage detected and wrapped with as.POSIXct(). This is to minimize the chance of assigning POSIXlt columns, which use 40+ bytes to store one date (versus 8 for POSIXct). Use as.POSIXct() (which will call strptime() as needed internally) to avoid this warning.")
11531153
as.POSIXct(base::strptime(x, ...))
11541154
}
11551155

inst/tests/tests.Rraw

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8236,7 +8236,7 @@ ll = list(a=as.POSIXlt("2015-01-01", tz='UTC'), b=1:5)
82368236
test(1612.1, as.data.table(ll), data.table(a=as.POSIXct("2015-01-01", tz='UTC'), b=1:5), warning="POSIXlt column type detected")
82378237
dt = data.table(d1="1984-03-17")
82388238
ans = data.table(d1="1984-03-17", d2=as.POSIXct("1984-03-17", tz='UTC'))
8239-
test(1612.2, dt[, d2 := strptime(d1, "%Y-%m-%d", tz='UTC')], ans, warning="POSIXlt column type detected and converted")
8239+
test(1612.2, dt[, d2 := strptime(d1, "%Y-%m-%d", tz='UTC')], ans, warning="strptime() usage detected and wrapped with as.POSIXct()")
82408240
ll = list(a=as.POSIXlt("2015-01-01"), b=2L)
82418241
test(1612.3, setDT(ll), error="Column 1 is of POSIXlt type")
82428242

0 commit comments

Comments
 (0)