Improved Error Message for Assigning NULL to List Column Items#6336
Improved Error Message for Assigning NULL to List Column Items#6336MichaelChirico merged 9 commits intomasterfrom
Conversation
|
Generated via commit c5947a0 Download link for the artifact containing the test results: ↓ atime-results.zip Time taken to finish the standard R installation steps: 11 minutes and 26 seconds Time taken to run |
src/assign.c
Outdated
| 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 when i is provided is not supported. If you intend to assign NULL to a column, use NULL without i. For list columns, if you intend to assign NULL to a specific item, use list(list(NULL)) in your query.")); // #1082, #3089 |
There was a problem hiding this comment.
Not sure I'm a fan of the wording chosen here:
Direct assignment of NULL when i is provided is not supported.
Well, it's never supported to assign NULL to anything but a list column -- regardless of whether i is provided.
If you intend to assign NULL to a column, use NULL without i
Is that right? Assigning NULL without i just deletes the column? And again, this only applies to list columns.
There was a problem hiding this comment.
Would it be ideal if we errored differently depending on whether LHS is a list column or not?
Something like:
DT = data.table(A=1:3, B=list())
DT[2, A:=NULL] # ERROR: When deleting columns, i should not be provided
DT[2, B:=NULL} # ERROR: When deleting columns, i should not be provided. If you are trying to assign NULL to a list column, please use list(list(NULL)) in your query instead.There was a problem hiding this comment.
yes that's exactly what I'm thinking. I ran out of time to check earlier -- IINM at that point in the code we haven't checked if the current column exists or not yet.
e.g. in your example
DT[2, C := NULL]
There was a problem hiding this comment.
WDYT about:
if (isNull(thisvalue) && !isNull(rows)) {
if (TYPEOF(VECTOR_ELT(dt, coln)) == VECSXP) {
error(_("When deleting columns, i should not be provided. If you are trying to assign NULL to a list column, please use list(list(NULL)) instead."));
} else {
error(_("When deleting columns, i should not be provided."));
}
}For the case where the column doesn't exist, I believe the error is the same as current master, ERROR: When deleting columns, i should not be provided.
There was a problem hiding this comment.
We also need to be sure coln < length(dt), but that's roughly the idea. PTAL.

Description:
This PR improves the error which occurs when attempting to assign
NULLto a list column item usingset()or:=. which is not supported, The new message guides users to uselist(list(NULL))instead for row-specific assignments, enhancing clarity and preventing common mistakes.Changes:
assign.cto provide a clearer instruction.New Error Message:
Issue Reference:
This PR closes #5526