Skip to content

Commit

Permalink
dots were not passed along to as.IDate/as.ITime in IDateTime method. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JenspederM committed Aug 21, 2021
1 parent 26394bc commit a87c9b0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@
# 2: 2 0.5
```

38. `IDateTime()` ignored the `tz=` and `format=` arguments because `...` was not passed through to submethods, [#2402](https://github.com/Rdatatable/data.table/pull/2402). Thanks to Frank Narf for reporting, and Jens Peder Meldgaard for the PR.

```
IDateTime("20171002095500", format="%Y%m%d%H%M%S")
# was :
# Error in charToDate(x) :
# character string is not in a standard unambiguous format
# now :
# idate itime
# <IDat> <ITime>
# 1: 2017-10-02 09:55:00
```

## NOTES

1. New feature 29 in v1.12.4 (Oct 2019) introduced zero-copy coercion. Our thinking is that requiring you to get the type right in the case of `0` (type double) vs `0L` (type integer) is too inconvenient for you the user. So such coercions happen in `data.table` automatically without warning. Thanks to zero-copy coercion there is no speed penalty, even when calling `set()` many times in a loop, so there's no speed penalty to warn you about either. However, we believe that assigning a character value such as `"2"` into an integer column is more likely to be a user mistake that you would like to be warned about. The type difference (character vs integer) may be the only clue that you have selected the wrong column, or typed the wrong variable to be assigned to that column. For this reason we view character to numeric-like coercion differently and will warn about it. If it is correct, then the warning is intended to nudge you to wrap the RHS with `as.<type>()` so that it is clear to readers of your code that a coercion from character to that type is intended. For example :
Expand Down
2 changes: 1 addition & 1 deletion R/IDateTime.R
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ mean.ITime = seq.ITime = c.ITime = function(x, ...) as.ITime(NextMethod())

IDateTime = function(x, ...) UseMethod("IDateTime")
IDateTime.default = function(x, ...) {
data.table(idate = as.IDate(x), itime = as.ITime(x))
data.table(idate = as.IDate(x, ...), itime = as.ITime(x, ...))
}

# POSIXt support
Expand Down
1 change: 1 addition & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -10236,6 +10236,7 @@ test(1689.2, as.IDate(date_tz), output="2016-01-13")
date_tz = structure(1496275200.11903, class = c("POSIXct", "POSIXt"), tzone = "America/Los_Angeles")
test(1689.3, as.character(as.IDate(date_tz)), "2017-05-31")
test(1689.4, as.character(as.IDate(date_tz, tz="UTC")), "2017-06-01")
test(1689.5, IDateTime("20171002095512", format="%Y%m%d%H%M%S"), data.table(idate=as.IDate("2017-10-02"), itime=as.ITime("09:55:12"))) #2402

# fix for #1766 and #1704
A = data.table(i = 1:6, j = rep(1:2, 3), x = letters[1:6], key = "i")
Expand Down

0 comments on commit a87c9b0

Please sign in to comment.