Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

2. `set()` now automatically pre-allocates new column slots if needed, similar to what `:=` already does, [#1831](https://github.com/Rdatatable/data.table/issues/1831) [#4100](https://github.com/Rdatatable/data.table/issues/4100). Thanks to @zachokeeffe and @tyner for the report and @ben-schwen for the fix.

3. `fcoalesce()` and `setcoalesce()` now allow mixing of `Date` and `IDate` classes, and mixing of `integer` and `double` types (coercing to `double` if needed), [#7463](https://github.com/Rdatatable/data.table/issues/7463). Thanks @akshkaushik for the report and the fix.

## data.table [v1.18.0](https://github.com/Rdatatable/data.table/milestone/37?closed=1) 23 December 2025

### BREAKING CHANGE
Expand Down
25 changes: 22 additions & 3 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -15628,8 +15628,8 @@ test(2060.202, fcoalesce(fkt), fkt)
test(2060.203, fcoalesce(bool, 1L), error='Item 2 is type integer but the first item is type logical. Please coerce before coalescing')
test(2060.204, fcoalesce(bool, NA_integer_), error='Item 2 is type integer but the first item is type logical.')
test(2060.205, fcoalesce(fkt, 1L), error='Item 1 is a factor but item 2 is not a factor. When factors are involved, all items must be factor')
test(2060.206, fcoalesce(num, 3L), error='Item 2 is type integer but the first item is type double')
test(2060.207, fcoalesce(int, 3), error='Item 2 is type double but the first item is type integer')
test(2060.206, fcoalesce(num, 3L), num_val)
test(2060.207, fcoalesce(int, 3), num_val)
test(2060.208, fcoalesce(fkt, 'b'), error='Item 1 is a factor but item 2 is not a factor. When factors are involved, all items must be factor.')
test(2060.209, fcoalesce(str, factor('b')), error='Item 2 is a factor but item 1 is not a factor. When factors are involved, all items must be factor')
test(2060.212, fcoalesce(list(1), list(2)), error="The first argument is a list, data.table or data.frame. In this case there should be no other arguments provided.")
Expand All @@ -15653,7 +15653,7 @@ if (test_bit64) {
test(2060.302, as.character(fcoalesce(int64, as.integer64(NA), as.integer64(3))), as.character(int64_val))
test(2060.303, as.character(fcoalesce(int64, as.integer64(rep(3, 4L)))), as.character(int64_val))
test(2060.304, fcoalesce(int64, 1), error='Item 2 has a different class than item 1')
test(2060.305, fcoalesce(int64, 1L), error = 'Item 2 is type integer but the first item is type double')
test(2060.305, fcoalesce(int64, 1L), error = 'Item 2 has a different class than item 1.')
}
# 2060.401-405 tested nanotime moved to other.Rraw 23, #5516
# setcoalesce
Expand Down Expand Up @@ -20607,6 +20607,7 @@ test(2294.59,
VDate = fifelse(VDate == as.Date("3000-01-01"), as.Date(NA), VDate),
VIDate = fifelse(VIDate == as.IDate("3000-01-01"), as.IDate(NA), VIDate),
VNumA, VNumB, Count, Y_Sum)])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please no formatting changes.

# 60. label is a scalar with class not matching any variable in 'by'.
test(2294.60,
groupingsets(DT1, .(Count = .N, Y_Sum = sum(Y)),
Expand Down Expand Up @@ -21968,3 +21969,21 @@ test(2356.2, options=c(datatable.alloccol=1L), set(DT, j="c", value=3), data.tab
# ensure := and set are consistent if they need to overallocate
DT = data.table(); DT2 = data.table()
test(2356.3, options=c(datatable.alloccol=1L), {for (i in seq(10L)) set(DT, j = sprintf("V%d",i), value = i); DT}, {for (i in seq(10)) DT2[, sprintf("V%d",i) := i]; DT2})

# fcoalesce Date and IDate mixing, #7463
test(2357.1, fcoalesce(as.Date("2026-01-01"), as.IDate("2026-01-02")), as.Date("2026-01-01"))
test(2357.2, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please dont make tests super complicated. {} should only be used when you are confident that it makes the test easier to read and you necessarily need multiple state. this is probably not warranted.

res = fcoalesce(as.IDate("2026-01-02"), as.Date("2026-01-01"))
list(res, class(res))
}, list(as.double(as.IDate("2026-01-02")), c("IDate", "Date"))) # promoted to double
test(2357.3, fcoalesce(1L, 2.0), 1.0)
test(2357.4, fcoalesce(2.0, 1L), 2.0)
test(2357.5, {
r = c(NA_real_, 2.0)
setcoalesce(r, 1L)
r
}, c(1.0, 2.0))
test(2357.6, {
i = c(NA_integer_, 2L)
setcoalesce(i, 1.0)
}, error="In-place coalesce cannot promote integer to double")
Loading
Loading