Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Error Message for Assigning NULL to List Column Items #6336

Merged
merged 9 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -186,6 +186,8 @@ This feature resolves [#4387](https://github.com/Rdatatable/data.table/issues/43

24. The internal `init()` function in `fread.c` module has been marked as `static`, [#6328](https://github.com/Rdatatable/data.table/pull/6328). This is to avoid name collisions, and the resulting segfaults, with other libraries that might expose the same symbol name, and be already loaded by the R process. This was observed in Cray HPE environments where the `libsci` library providing LAPACK to R already has an `init` symbol. Thanks to @rtobar for the report and fix.

25. `set()` and `:=` now provide an improved error message when attempting to directly assign `NULL` to a list column item. The new message guides users to use `list(list(NULL))` instead, enhancing clarity and preventing common mistakes. Previously, this operation would throw a generic error, but now the message is more informative and helpful. Thanks to @Nj221102 for the implementation and @MichaelChirico for the suggestion.

## TRANSLATIONS

1. Fix a typo in a Mandarin translation of an error message that was hiding the actual error message, [#6172](https://github.com/Rdatatable/data.table/issues/6172). Thanks @trafficfan for the report and @MichaelChirico for the fix.
Expand Down
8 changes: 4 additions & 4 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -5578,8 +5578,8 @@ test(1352.8, DT[,sum(b),by=.(a%%2,c)], DT[,sum(b),by=list(a%%2,c)])

# that :=NULL together with i is now an error
DT = data.table(a=1:3, b=1:6)
test(1353.1, DT[2, b:=NULL], error="When deleting columns, i should not be provided")
test(1353.2, DT[2, c("a","b"):=list(42, NULL)], error="When deleting columns, i should not be provided")
test(1353.1, DT[2, b:=NULL], error=".*Direct assignment of NULL to a list column item is not supported.*")
test(1353.2, DT[2, c("a","b"):=list(42, NULL)], error=".*Direct assignment of NULL to a list column item is not supported.*")

# order optimisation caused trouble due to chaining because of 'substitute(x)' usage in [.data.table.
set.seed(1L)
Expand Down Expand Up @@ -7243,7 +7243,7 @@ if (test_bit64) {
# fix for #1082
dt1 = data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9, key=c("x", "y"))
dt2 = copy(dt1)
test(1502.1, dt1["a", z := NULL], error="When deleting columns, i should not be provided")
test(1502.1, dt1["a", z := NULL], error=".*Direct assignment of NULL to a list column item is not supported.*")
# this shouldn't segfault on 'dt1[...]'
test(1502.2, dt1["a", z := 42L], dt2["a", z := 42L])

Expand Down Expand Up @@ -13235,7 +13235,7 @@ test(1946, unique(DT, by="B"), data.table(A=1:3, B=1:3, foo=7:9))

# corruption when deleting a missing column and providing i too, #3089
DT = data.table(A=1:5)
test(1947.1, DT[A<0, c('A','B'):=.(NULL, A)], error="When deleting columns, i should not be provided")
test(1947.1, DT[A<0, c('A','B'):=.(NULL, A)], error=".*Direct assignment of NULL to a list column item is not supported.*")
test(1947.2, DT, data.table(A=1:5))

## tests for backticks and spaces in column names of on=, #2931
Expand Down
2 changes: 1 addition & 1 deletion src/assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ SEXP assign(SEXP dt, SEXP rows, SEXP cols, SEXP newcolnames, SEXP values)
coln--;
SEXP thisvalue = RHS_list_of_columns ? VECTOR_ELT(values, i) : values;
vlen = length(thisvalue);
if (isNull(thisvalue) && !isNull(rows)) error(_("When deleting columns, i should not be provided")); // #1082, #3089
if (isNull(thisvalue) && !isNull(rows)) error(_("Direct assignment of NULL to a list column item is not supported. If you intend to assign NULL to an item in the list column, use list(list(NULL)) in your query.")); // #1082, #3089
Nj221102 marked this conversation as resolved.
Show resolved Hide resolved
if (coln+1 <= oldncol) colnam = STRING_ELT(names,coln);
else colnam = STRING_ELT(newcolnames,coln-length(names));
if (coln+1 <= oldncol && isNull(thisvalue)) continue; // delete existing column(s) afterwards, near end of this function
Expand Down
Loading