PapaParse: CSV parsing is broken in 5.4.1
Hi everyone,
First of all, big thanks for this great library that’s been a big help in my work 🙌
I noticed when going from 5.3.2 to 5.4.1 that some CSV files can’t be parsed successfully anymore. I’ll attach below a small CSV, a nodejs script to reproduce the issue as well as the output.
example.csv:
colName_2,colName_3,another_col,entity,some_bool,period,date,value_eur
"foo, bar","foo, bar",foo_bar_baz_V1,bar baz,0,2022_02,02/01/22,1234.45678
"foo, bar","foo, bar",foo_bar_baz_V1,bar baz,0,2022_03,03/01/22,1234.45678
"foo, bar","foo, bar",foo_bar_baz_V2,bar baz,0,2022_11,11/01/22,-12345.67891
"foo, bar","foo, bar",foo_bar_baz_V2,bar baz,0,2022_12,12/01/22,-12345.67891
script.js:
const papa = require('papaparse');
const fs = require('fs');
const readStream = fs.createReadStream(`${ __dirname }/example.csv`);
return papa.parse(readStream, {
step: (res, parser) => {
parser.pause();
Object.keys(res.data).
sort().
forEach((key) => {
console.log(res.data[key]);
});
return parser.resume();
}, // step
header: true,
error: (err) => {
return console.error(err);
}, // error
complete: () => {
console.log('finished');
}, // complete
}); // return papa.parse
Output with papaparse 5.4.1:
$ node script.js
foo_bar_baz_V1
foo, bar
foo, bar
02/01/22
bar baz
2022_02
0
1234.45678
[ '-12345.67891' ]
foo, bar
foo, bar
foo_1, bar"_1,foo_bar_baz_V1,bar baz,0,2022_03,03/01/22,1234.45678
"foo, bar
2022_11
foo_bar_baz_V2
0
bar baz
11/01/22
foo, bar"_1,foo_bar_baz_V2,bar baz,0,2022_12,12/01/22,-12345.67891
bar"
finished
Let me know if you need any additional information to better capture the issue.
Thanks a bunch.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 4
- Comments: 28
Follow-up – downgrading to papaparse 5.3.2 corrected the problem.
I’m experiencing exactly what @ulo described above. Streaming on 5.4.1 with
header: true, the first 16 rows come back fine. The 17th row and beyond are parsed incorrectly.Converting the stream to a string and parsing that works as expected.
I can repro. this on a very simple implementation.
Emit a dataset like this from a stream.
Details don’t matter, it just needs a unique header and more than 16 rows, and the next row should have a duplicate header to see the bad parsing behavior.
Then consume the stream…
Or
At row 16 or 17, you’ll get a warning on stderr that says “Duplicate headers found and renamed.” indicating it has seemingly forgotten the headers it parsed at the beginning of the stream. Then it treats the next row like a new set of headers.
The
_1value strikes me as similar to data issues found in #985.The symptoms are:
_1appended to them for no apparent reasonMaybe to illustrate the point better, here’s the output from the same script but using papaparse 5.3.2 :
@jbool24 Yeah I don’t have a use for it and would in general not want to use it. I would not be sad if it was removed. But I don’t know anything about whatever use cases resulted it in being added so I’m trying to be open minded about it. I wouldn’t be sad if it was just ripped out. But if it is to stay in I think it should be an option that defaults to ‘off’.
This is because you have duplicated Headers. Is a new feature introduced in the newer version.
Having the same issue. step works fine if I don’t pause the parser, but rows are not parsed properly with parser.pause().
Run the code below with parser.pause and parser.resume commented out, and not commented out, to compare the output.
Theraphosidae 20241116.csv
Csv parsing still broken on NodeJS, using v5.4.1 with header: true. Wrong number of rows and invalid row objects filled with “_1”, “_2”, etc… and concatenated columns that should be distinct values. The csv file used is valid and parsed correctly using different csv tools.
EDIT: The bug appears when using the stream mode like this:
Using
looks to work fine (though Typescript complains on the 1st arg of the parse function but that’s maybe some misconfiguration on our side).