Skip to content

Commit bcc4855

Browse files
authored
Computed Columns should write to only filtered rows (#5709)
* fix empty filter, default to generatedFilter instead of all true * overwrite only filtered rows if exactly filtered amount of data for computed column fixes jasp-stats/jasp-issues#2972 ([Bug]: PC scores added on wrong row if data have pass-through filters)
1 parent 5393936 commit bcc4855

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CommonData/column.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,21 @@ bool Column::overwriteDataAndType(stringvec data, columnType colType)
598598
JASPTIMER_SCOPE(Column::overwriteDataAndType);
599599

600600
if(data.size() != _data->rowCount())
601-
data.resize(_data->rowCount());
601+
{
602+
if(data.size() == _data->filter()->filteredRowCount())
603+
{
604+
const boolvec & filtered = _data->filter()->filtered();
605+
stringvec newData;
606+
newData . reserve(filtered.size());
607+
608+
for(size_t iFilter=0, iData=0; iFilter < filtered.size() && iData < data.size(); iFilter++)
609+
newData.push_back(filtered[iFilter] ? data[iData++] : "");
610+
611+
data = newData;
612+
}
613+
else
614+
data.resize(_data->rowCount());
615+
}
602616

603617
bool changes = _type != colType;
604618
setValues(data, data, 0, &changes);

Desktop/engine/enginerepresentation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ void EngineRepresentation::runScriptOnProcess(RFilterStore * filterStore)
331331

332332
_lastRequestId = filterStore->requestId;
333333

334-
QString dataFilter = filterStore->script == "" ? "*" : filterStore->script;
334+
QString dataFilter = filterStore->script == "" ? "generatedFilter" : filterStore->script;
335335
json["filter"] = dataFilter.toStdString();
336336

337337
Log::log() << "sending filter with requestID " << filterStore->requestId << " to engine" << std::endl;

R-Interface/jasprcpp.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,7 @@ bool _jaspRCPP_setColumnDataAndType(const std::string & columnName, Rcpp::RObjec
840840
for(size_t i=0; i<convertedStrings.size(); i++)
841841
{
842842
bool isNA = convertedStrings[i] == "NA",
843-
isLgl = convertedStrings[i] == "TRUE" || convertedStrings[i] == "FALSE",
844-
isNan = std::isnan(dblData[i]);
843+
isLgl = convertedStrings[i] == "TRUE" || convertedStrings[i] == "FALSE";
845844

846845
nominals[i] = std::isnan(dblData[i]) // If the string could not be converted to a number its not TRUE or FALSE, but it might be NA. We do not want that as a result!
847846
? (!isNA ? convertedStrings[i].c_str() : "")

0 commit comments

Comments
 (0)