-
Notifications
You must be signed in to change notification settings - Fork 1k
Align melt with docs for list measure.vars #7257
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8280e2d
use integer indices for measure.vars and error on non scalar aggregates
Mukulyadav2004 7e02a0d
1037 - 404 and 407
Mukulyadav2004 5abd761
remove nws item
Mukulyadav2004 e3b8a64
removed extra multiple value column loop
Mukulyadav2004 4d283ba
revert fcast modifications
Mukulyadav2004 879198c
keep non list path
Mukulyadav2004 ed1712e
revert
Mukulyadav2004 c0e03ed
delete multiple output column else branch
Mukulyadav2004 3f0e0a8
Fix test cases
Mukulyadav2004 c16469b
closed bracket
Mukulyadav2004 f552d56
EXPECT INTEGER
Mukulyadav2004 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -598,31 +598,42 @@ SEXP getvarcols(SEXP DT, SEXP dtnames, Rboolean varfactor, Rboolean verbose, str | |
| if (data->lvalues==1 && length(VECTOR_ELT(data->valuecols, 0)) != data->lmax) | ||
| internal_error(__func__, "getvarcols %d %d", length(VECTOR_ELT(data->valuecols, 0)), data->lmax); // # nocov | ||
| if (isNull(data->variable_table)) { | ||
| if ((data->lvalues == 1) & data->measure_is_list) { | ||
| warning(_("measure.vars is a list with length=1, which as long documented should return integer indices in the 'variable' column, but currently returns character column names. To increase consistency in the next release, we plan to change 'variable' to integer, so users who were relying on this behavior should change measure.vars=list('col_name') (output variable is column name now, but will become column index/integer) to measure.vars='col_name' (variable is column name before and after the planned change).")); | ||
| } | ||
| if (!varfactor) { | ||
| SET_VECTOR_ELT(ansvars, 0, target=allocVector(STRSXP, data->totlen)); | ||
| if (data->lvalues == 1) {//one value column to output. TODO #5247 change to !data->measure_is_list | ||
| if (data->measure_is_list) { | ||
| // Return integer indices for list measure.vars (consistency with docs) | ||
| SET_VECTOR_ELT(ansvars, 0, target=allocVector(INTSXP, data->totlen)); | ||
| int *td = INTEGER(target); | ||
| for (int j=0, ansloc=0; j<data->lmax; ++j) { | ||
| const int thislen = data->narm ? length(VECTOR_ELT(data->not_NA_indices, j)) : data->nrow; | ||
| for (int k=0; k<thislen; ++k) td[ansloc++] = j+1; | ||
| } | ||
| } else { | ||
| // same behavior for vector measure.vars: variable is column names | ||
| SET_VECTOR_ELT(ansvars, 0, target=allocVector(STRSXP, data->totlen)); | ||
| const int *thisvaluecols = INTEGER(VECTOR_ELT(data->valuecols, 0)); | ||
| for (int j=0, ansloc=0; j<data->lmax; ++j) { | ||
| const int thislen = data->narm ? length(VECTOR_ELT(data->not_NA_indices, j)) : data->nrow; | ||
| SEXP str = STRING_ELT(dtnames, thisvaluecols[j]-1); | ||
| for (int k=0; k<thislen; ++k) SET_STRING_ELT(target, ansloc++, str); | ||
| } | ||
| } else {//multiple value columns to output. | ||
| for (int j=0, ansloc=0, level=1; j<data->lmax; ++j) { | ||
| const int thislen = data->narm ? length(VECTOR_ELT(data->not_NA_indices, j)) : data->nrow; | ||
| char buff[20]; | ||
| snprintf(buff, sizeof(buff), "%d", level++); // # notranslate | ||
| for (int k=0; k<thislen; ++k) SET_STRING_ELT(target, ansloc++, mkChar(buff)); | ||
| } | ||
| } | ||
| } else {// varfactor==TRUE | ||
| SET_VECTOR_ELT(ansvars, 0, target=allocVector(INTSXP, data->totlen)); | ||
| SEXP levels; | ||
| int *td = INTEGER(target); | ||
| if (data->lvalues == 1) {//one value column to output. TODO #5247 change to !data->measure_is_list | ||
| if (data->measure_is_list) { | ||
| int nlevel = data->lmax; | ||
| levels = PROTECT(allocVector(STRSXP, nlevel)); protecti++; | ||
| for (int j=0; j<nlevel; ++j) { | ||
| char buff[20]; | ||
| snprintf(buff, sizeof(buff), "%d", j+1); // # notranslate | ||
| SET_STRING_ELT(levels, j, mkChar(buff)); | ||
| } | ||
| for (int j=0, ansloc=0; j<data->lmax; ++j) { | ||
| const int thislen = data->narm ? length(VECTOR_ELT(data->not_NA_indices, j)) : data->nrow; | ||
| for (int k=0; k<thislen; ++k) td[ansloc++] = j+1; | ||
| } | ||
| } else { // non-list measure.vars keeps legacy name-based levels | ||
| SEXP thisvaluecols = VECTOR_ELT(data->valuecols, 0); | ||
| int len = length(thisvaluecols); | ||
| levels = PROTECT(allocVector(STRSXP, len)); protecti++; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please revert these changes and instead use the approach here https://github.com/Rdatatable/data.table/pull/5247/files |
||
|
|
@@ -645,16 +656,6 @@ SEXP getvarcols(SEXP DT, SEXP dtnames, Rboolean varfactor, Rboolean verbose, str | |
| const int thislen = data->narm ? length(VECTOR_ELT(data->not_NA_indices, j)) : data->nrow; | ||
| for (int k=0; k<thislen; ++k) td[ansloc++] = md[j]; | ||
| } | ||
| } else {//multiple output columns. | ||
| int nlevel=0; | ||
| levels = PROTECT(allocVector(STRSXP, data->lmax)); protecti++; | ||
| for (int j=0, ansloc=0; j<data->lmax; ++j) { | ||
| const int thislen = data->narm ? length(VECTOR_ELT(data->not_NA_indices, j)) : data->nrow; | ||
| char buff[20]; | ||
| snprintf(buff, sizeof(buff), "%d", nlevel + 1); // # notranslate | ||
| SET_STRING_ELT(levels, nlevel++, mkChar(buff)); // generate levels = 1:nlevels | ||
| for (int k=0; k<thislen; ++k) td[ansloc++] = nlevel; | ||
| } | ||
| } | ||
| setAttrib(target, R_LevelsSymbol, levels); | ||
| setAttrib(target, R_ClassSymbol, ScalarString(char_factor)); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add these tests from the other pr