Skip to content

Commit

Permalink
Improve row skipping performance (#911) (#912)
Browse files Browse the repository at this point in the history
Co-authored-by: Aleks Bezrodnov <aleksei.bezrodnov@zalando.de>
  • Loading branch information
bezrodnov and Aleks Bezrodnov committed Mar 15, 2022
1 parent 4132d81 commit a93c5c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
6 changes: 3 additions & 3 deletions papaparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1163,9 +1163,9 @@ License: MIT

if (_config.skipEmptyLines)
{
for (var i = 0; i < _results.data.length; i++)
if (testEmptyLine(_results.data[i]))
_results.data.splice(i--, 1);
_results.data = _results.data.filter(function(d) {
return !testEmptyLine(d);
});
}

if (needsHeaderRow())
Expand Down
29 changes: 27 additions & 2 deletions tests/test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,31 @@ var PARSE_ASYNC_TESTS = [
data: [['A','B','C'],['X','Y','Z']],
errors: []
}
},
{
description: "File with a few regular and lots of empty lines",
disabled: !FILES_ENABLED,
input: FILES_ENABLED ? new File(["A,B,C\nX,Y,Z\n" + new Array(500000).fill(",,").join("\n")], "sample.csv") : false,
config: {
skipEmptyLines: "greedy"
},
expected: {
data: [['A','B','C'],['X','Y','Z']],
errors: []
}
},
{
description: "File with a few regular and lots of empty lines + worker",
disabled: !FILES_ENABLED,
input: FILES_ENABLED ? new File(["A,B,C\nX,Y,Z\n" + new Array(500000).fill(",,").join("\n")], "sample.csv") : false,
config: {
worker: true,
skipEmptyLines: "greedy"
},
expected: {
data: [['A','B','C'],['X','Y','Z']],
errors: []
}
}
];

Expand Down Expand Up @@ -1836,9 +1861,9 @@ var UNPARSE_TESTS = [
},
{
description: "Returns without rows with no content when skipEmptyLines is 'greedy'",
input: [[null, ' '], [], ['1', '2']],
input: [[null, ' '], [], ['1', '2']].concat(new Array(500000).fill(['', ''])).concat([['3', '4']]),
config: {skipEmptyLines: 'greedy'},
expected: '1,2'
expected: '1,2\r\n3,4'
},
{
description: "Returns empty rows when empty rows are passed and skipEmptyLines is false with headers",
Expand Down

0 comments on commit a93c5c9

Please sign in to comment.