Skip to content

Commit 22240b7

Browse files
committed
various tests for consistency
1 parent 1a18d6b commit 22240b7

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

inst/tests/tests.Rraw

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18617,27 +18617,54 @@ test(2263.6, options=list(datatable.verbose=TRUE, datatable.optimize=Inf), names
1861718617
DT = data.table(L = list("A"), i = 1L)
1861818618
DT$L = list(NULL)
1861918619
# Test replacement of a list column with list(NULL) using $ to access the column
18620-
test(2264.1, DT, data.table(L = list(NULL), i = 1L))
18620+
test(2264.01, DT, data.table(L = list(NULL), i = 1L))
1862118621
DT = data.table(L = list("A"), i = 1L)
1862218622
# Test same replacement but with LHS := RHS operator
18623-
test(2264.2, DT[, L := list(NULL)], data.table(L = list(NULL), i = 1L))
18623+
test(2264.02, DT[, L := list(NULL)], data.table(L = list(NULL), i = 1L))
1862418624
DT = data.table(L = list("A"), i = 1L)
1862518625
DT1 = data.table(L = list("A"), i = 1L)
1862618626
# Test that := operator and functional form `:=` have the same result
18627-
test(2264.3, DT[, L := list(NULL)], DT1[, `:=`(L = list(NULL))])
18627+
test(2264.03, DT[, L := list(NULL)], DT1[, `:=`(L = list(NULL))])
1862818628
DT = data.table(L = list("A"), i = 1L)
1862918629
DT1 = data.table(L = list("A"), i = 1L)
1863018630
# Test that functional operator and let have the same result
18631-
test(2264.4, DT[, `:=`(L = list(NULL))], DT1[, let(L = list(NULL))])
18631+
test(2264.04, DT[, `:=`(L = list(NULL))], DT1[, let(L = list(NULL))])
1863218632
# Similar tests below but DT list column has more than one entry
1863318633
DT = data.table(L = list("B", "C"), i = 1L)
1863418634
DT$L = list(NULL)
18635-
test(2264.5, DT, data.table(L = list(NULL, NULL), i = 1L))
18635+
test(2264.05, DT, data.table(L = list(NULL, NULL), i = 1L))
1863618636
DT = data.table(L = list("B", "C"), i = 1L)
18637-
test(2264.6, DT[, L := list(NULL)], data.table(L = list(NULL, NULL), i = 1L))
18637+
test(2264.06, DT[, L := list(NULL)], data.table(L = list(NULL, NULL), i = 1L))
1863818638
DT = data.table(L = list("B", "C"), i = 1L)
1863918639
DT1 = data.table(L = list("B", "C"), i = 1L)
18640-
test(2264.7, DT[, L := list(NULL)], DT1[, `:=`(L = list(NULL))])
18640+
test(2264.07, DT[, L := list(NULL)], DT1[, `:=`(L = list(NULL))])
1864118641
DT = data.table(L = list("B", "C"), i = 1L)
1864218642
DT1 = data.table(L = list("B", "C"), i = 1L)
18643-
test(2264.8, DT[, `:=`(L = list(NULL))], DT1[, let(L = list(NULL))])
18643+
test(2264.08, DT[, `:=`(L = list(NULL))], DT1[, let(L = list(NULL))])
18644+
# Tests for add/remove columns
18645+
DT = data.table(L = list("B"), i = 1L)
18646+
# warns, does not add
18647+
DT$new = list(NULL)
18648+
test(2264.09, DT, data.table(L = list("B"), i = 1L))
18649+
test(2264.10, copy(DT)[, D := list(NULL)], data.table(L = list("B"), i = 1L), warning="Tried to assign NULL to column 'D', but this column does not exist to remove")
18650+
# works, adds in functional form
18651+
test(2264.11, copy(DT)[, `:=`(D = list(NULL))], data.table(L = list("B"), i = 1L, D = list(NULL)))
18652+
# remove list column, must use NULL instead of list(NULL)
18653+
test(2264.12, copy(DT)[, L := NULL], data.table(i = 1L))
18654+
# remove non-list column, same as old
18655+
test(2264.13, copy(DT)[, i := NULL], data.table(L = list("B")))
18656+
# Same tests, with multiple rows
18657+
DT = data.table(L = list("B", "C"), i = 1L)
18658+
test(2264.14, copy(DT)[, D := list(NULL)], data.table(L = list("B", "C"), i = 1L), warning="Tried to assign NULL to column 'D', but this column does not exist to remove")
18659+
test(2264.15, copy(DT)[, `:=`(D = list(NULL))], data.table(L = list("B", "C"), i = 1L, D = list(NULL)))
18660+
test(2264.16, copy(DT)[, L := NULL], data.table(i = c(1L, 1L)))
18661+
test(2264.17, copy(DT)[, i := NULL], data.table(L = list("B", "C")))
18662+
# test for deleting a list column and adding a new empty list column in the same query, same as before
18663+
test(2264.18, copy(DT)[, c("L", "D") := list(NULL, list(NULL))], data.table(i = c(1L, 1L), D = list(NULL)))
18664+
# test for deleting everything
18665+
test(2264.19, copy(DT)[, c("L", "i") := NULL], data.table())
18666+
# test for replacement of multiple empty list columns
18667+
DT = data.table(L1 = list("B", "C"), L2 = list("C", "D"), i = 1L)
18668+
test(2264.20, copy(DT)[, c("L1", "L2") := list(list(NULL), list(NULL))], data.table(L1 = list(NULL), L2 = list(NULL), i = c(1L, 1L)))
18669+
# test for removal of multiple empty list columns
18670+
test(2264.21, copy(DT)[, c("L1", "L2") := NULL], data.table(i = c(1L, 1L)))

src/assign.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values)
533533
coln = INTEGER(cols)[i]-1;
534534
SEXP thisvalue = RHS_list_of_columns ? VECTOR_ELT(values, i) : values;
535535
// if values is list(NULL), then replace with a list of NULLs instead of deleting, #5558
536-
if (RHS_list_of_columns && length(values)==1 && TYPEOF(VECTOR_ELT(values, 0))==NILSXP) {
536+
if (RHS_list_of_columns && length(values)==1 && TYPEOF(VECTOR_ELT(values, 0))==NILSXP && coln < oldncol) {
537537
SET_VECTOR_ELT(dt, coln, targetcol=allocNAVector(VECSXP, length(VECTOR_ELT(dt, coln))));
538538
continue;
539539
}

0 commit comments

Comments
 (0)