Skip to content

Commit 2aed4cc

Browse files
committed
merge master
2 parents 783d9d9 + 2f67531 commit 2aed4cc

File tree

10 files changed

+371
-96
lines changed

10 files changed

+371
-96
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ Authors@R: c(
7070
person("Kyle","Haynes", role="ctb"),
7171
person("Boniface Christian","Kamgang", role="ctb"),
7272
person("Olivier","Delmarcell", role="ctb"),
73-
person("Josh","O'Brien", role="ctb"))
73+
person("Josh","O'Brien", role="ctb"),
74+
person("Dereck","de Mezquita", role="ctb"))
7475
Depends: R (>= 3.1.0)
7576
Imports: methods
7677
Suggests: bit64 (>= 4.0.0), bit (>= 4.0.4), curl, R.utils, xts, nanotime, zoo (>= 1.8-1), yaml, knitr, rmarkdown, markdown

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ if (getRversion() >= "3.6.0") {
148148

149149
# IDateTime support:
150150
export(as.IDate,as.ITime,IDateTime)
151-
export(second,minute,hour,yday,wday,mday,week,isoweek,month,quarter,year)
151+
export(second,minute,hour,yday,wday,mday,week,isoweek,month,quarter,year,yearmon,yearqtr)
152152

153153
S3method("[", ITime)
154154
S3method("+", IDate)

NEWS.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@
274274

275275
37. `unique.data.table()` gains `cols` to specify a subset of columns to include in the resulting `data.table`, [#5243](https://github.com/Rdatatable/data.table/issues/5243). This saves the memory overhead of subsetting unneeded columns, and provides a cleaner API for a common operation previously needing more convoluted code. Thanks to @MichaelChirico for the suggestion & implementation.
276276

277-
38. `:=` is now optimized by group, [#1414](https://github.com/Rdatatable/data.table/issues/1414). Thanks to Arun Srinivasan for suggesting, and Benjamin Schwendinger for the PR.
277+
38. `:=` is now optimized by group, [#1414](https://github.com/Rdatatable/data.table/issues/1414). Thanks to Arun Srinivasan for suggesting, and Benjamin Schwendinger for the PR. Thanks to @clerousset, @dcaseykc, @OfekShilon, and @SeanShao98 for testing dev and filing detailed bug reports which were fixed before release and their tests added to the test suite.
278278

279279
39. `.I` is now available in `by` for rowwise operations, [#1732](https://github.com/Rdatatable/data.table/issues/1732). Thanks to Rafael H. M. Pereira for requesting, and Benjamin Schwendinger for the PR.
280280

@@ -292,7 +292,9 @@
292292
# 2: 2 10
293293
```
294294

295-
40. `first()` and `last()` gain `na.rm` taking values `FALSE` (default), `TRUE` or `"row"`, [#4239](https://github.com/Rdatatable/data.table/issues/4239). For vector input, `TRUE` and `"row"` are the same. For `data.table|frame` input, `TRUE` returns the first/last non-NA observation in each column, while `"row"` returns the first/last row where all columns are non-NA. `TRUE` is optimized by group and `"row"` may be optimized by group in future. `n>1` with `na.rm=TRUE` is also optimized by group. Thanks to Nicolas Bennett and Michael Chirico for the requests, and Benjamin Schwendinger for the PR.
295+
40. New functions `yearmon()` and `yearqtr` give a combined representation of `year()` and `month()`/`quarter()`. These and also `yday`, `wday`, `mday`, `week`, `month` and `year` are now optimized for memory and compute efficiency by removing the `POSIXlt` dependency, [#649](https://github.com/Rdatatable/data.table/issues/649). Thanks to Matt Dowle for the request, and Benjamin Schwendinger for the PR.
296+
297+
41. `first()` and `last()` gain `na.rm` taking values `FALSE` (default), `TRUE` or `"row"`, [#4239](https://github.com/Rdatatable/data.table/issues/4239). For vector input, `TRUE` and `"row"` are the same. For `data.table|frame` input, `TRUE` returns the first/last non-NA observation in each column, while `"row"` returns the first/last row where all columns are non-NA. `TRUE` is optimized by group and `"row"` may be optimized by group in future. `n>1` with `na.rm=TRUE` is also optimized by group. Thanks to Nicolas Bennett and Michael Chirico for the requests, and Benjamin Schwendinger for the PR.
296298

297299
```R
298300
x
@@ -616,6 +618,10 @@
616618

617619
51. `merge.data.table()` silently ignored the `incomparables` argument, [#2587](https://github.com/Rdatatable/data.table/issues/2587). It is now implemented and any other ignored arguments (e.g. misspellings) are now warned about. Thanks to @GBsuperman for the report and @ben-schwen for the fix.
618620

621+
52. `DT[, c('z','x') := {x=NULL; list(2,NULL)}]` now removes column `x` as expected rather than incorrectly assigning `2` to `x` as well as `z`, [#5284](https://github.com/Rdatatable/data.table/issues/5284). The `x=NULL` is superfluous while the `list(2,NULL)` is the final value of `{}` whose items correspond to `c('z','x')`. Thanks @eutwt for the report, and @ben-schwen for the fix.
622+
623+
53. `as.data.frame(DT, row.names=)` no longer silently ignores `row.names`, [#5319](https://github.com/Rdatatable/data.table/issues/5319). Thanks to @dereckdemezquita for the fix and PR, and @ben-schwen for guidance.
624+
619625
## NOTES
620626

621627
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 :

R/IDateTime.R

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,10 @@ hour = function(x) {
338338
if (inherits(x, 'ITime')) return(as.integer(x) %/% 3600L %% 24L)
339339
as.POSIXlt(x)$hour
340340
}
341-
yday = function(x) as.POSIXlt(x)$yday + 1L
342-
wday = function(x) (unclass(as.IDate(x)) + 4L) %% 7L + 1L
343-
mday = function(x) as.POSIXlt(x)$mday
344-
week = function(x) yday(x) %/% 7L + 1L
341+
yday = function(x) convertDate(as.IDate(x), "yday")
342+
wday = function(x) convertDate(as.IDate(x), "wday")
343+
mday = function(x) convertDate(as.IDate(x), "mday")
344+
week = function(x) convertDate(as.IDate(x), "week")
345345
isoweek = function(x) {
346346
# ISO 8601-conformant week, as described at
347347
# https://en.wikipedia.org/wiki/ISO_week_date
@@ -356,7 +356,13 @@ isoweek = function(x) {
356356
1L + (nearest_thurs - year_start) %/% 7L
357357
}
358358

359-
month = function(x) as.POSIXlt(x)$mon + 1L
360-
quarter = function(x) as.POSIXlt(x)$mon %/% 3L + 1L
361-
year = function(x) as.POSIXlt(x)$year + 1900L
359+
month = function(x) convertDate(as.IDate(x), "month")
360+
quarter = function(x) convertDate(as.IDate(x), "quarter")
361+
year = function(x) convertDate(as.IDate(x), "year")
362+
yearmon = function(x) convertDate(as.IDate(x), "yearmon")
363+
yearqtr = function(x) convertDate(as.IDate(x), "yearqtr")
362364

365+
convertDate = function(x, type) {
366+
type = match.arg(type, c("yday", "wday", "mday", "week", "month", "quarter", "year", "yearmon", "yearqtr"))
367+
.Call(CconvertDate, x, type)
368+
}

R/data.table.R

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ replace_dot_alias = function(e) {
13771377
} else if (address(jval) == address(SDenv$.SD)) {
13781378
jval = copy(jval)
13791379
} else if ( length(jcpy <- which(vapply_1c(jval, address) %chin% vapply_1c(SDenv, address))) ) {
1380-
for (jidx in jcpy) jval[[jidx]] = copy(jval[[jidx]])
1380+
for (jidx in jcpy) { if(!is.null(jval[[jidx]])) jval[[jidx]] = copy(jval[[jidx]]) }
13811381
} else if (jsub %iscall% 'get') {
13821382
jval = copy(jval) # fix for #1212
13831383
}
@@ -1925,9 +1925,10 @@ replace_dot_alias = function(e) {
19251925
vlen = length(ans[[1L]])
19261926
# replicate vals if GForce returns 1 value per group
19271927
jvals = if (vlen==length(len__)) lapply(tail(ans, -length(g)), rep, times=len__) else tail(ans, -length(g)) # see comment in #4245 for why rep instead of rep.int
1928-
jrows = if (!is.null(irows) && length(irows)!=length(o__)) irows else { if (length(o__)==0L) NULL else o__}
1929-
# unwrap single column jvals for assign
1930-
if (length(jvals)==1L) jvals = jvals[[1L]]
1928+
jrows = vecseq(f__,len__,NULL)
1929+
if (length(o__)) jrows = o__[jrows]
1930+
if (length(irows)) jrows = irows[jrows]
1931+
if (length(jvals)==1L) jvals = jvals[[1L]] # unwrap single column jvals for assign
19311932
.Call(Cassign, x, jrows, lhs, newnames, jvals)
19321933
}
19331934
if (any(names_x[cols] %chin% key(x)))
@@ -2224,15 +2225,9 @@ tail.data.table = function(x, n=6L, ...) {
22242225
set(x,j=name,value=value) # important i is missing here
22252226
}
22262227

2227-
as.data.frame.data.table = function(x, ...)
2228+
as.data.frame.data.table = function(x, row.names = NULL, ...)
22282229
{
2229-
ans = copy(x)
2230-
setattr(ans,"row.names",.set_row_names(nrow(x))) # since R 2.4.0, data.frames can have non-character row names
2231-
setattr(ans,"class","data.frame")
2232-
setattr(ans,"sorted",NULL) # remove so if you convert to df, do something, and convert back, it is not sorted
2233-
setattr(ans,"index",NULL) #4889 #5042
2234-
setattr(ans,".internal.selfref",NULL)
2235-
# leave tl intact, no harm,
2230+
ans = setDF(copy(x), rownames = row.names) # issue #5319
22362231
ans
22372232
}
22382233

inst/tests/test2233-43.Rdata

351 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)