question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

parsing gets wrong if first line begins with a comma

See original GitHub issue

Just check the following:

papa.parse(',"a","b"\n,,"c","d,e",,34,')

The delimiter is the comma, this is OK. But the parsed first line includes just one column that encompasses the whole string ',"a","b"'

The problem seems to happen with the first line only, leading commas in subsequent lines make no hassle.

In the program where I use papaparse, I fixed this problem by adding a leading "" if the string starts with a comma, hence I get

papa.parse('"","a","b"\n,,"c","d,e",,34,')

which works OK

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

1reaction
tuananhcommented, Mar 16, 2020

Ah i get the same issue. is there any workaround ?

0reactions
martinffostercommented, Sep 11, 2019

I tripped across this bug today. This note is to add another test case: it occurs on any row starting with the delimiter. Eg with header: true:

OK:

Column 1,Column 2,Column 3,Column 4
1-1,1-2,1-3,1-4
1-2,2-2,2-3,2-4

error:

Column 1,Column 2,Column 3,Column 4
,1-2,1-3,1-4
1-2,2-2,2-3,2-4

error:

Column 1,Column 2,Column 3,Column 4
1-1,1-2,1-3,1-4
,2-2,2-3,2-4

error:

Column 1,Column 2,Column 3,Column 4
,1-2,1-3,1-4
,2-2,2-3,2-4

The header row always gets correctly parsed. The error is all the same, a variant of:

{type: "FieldMismatch", code: "TooFewFields", message: "Too few fields: expected 4 fields but parsed 1", row: 2}
code: "TooFewFields"
message: "Too few fields: expected 4 fields but parsed 1"
row: 2
type: "FieldMismatch"
__proto__: Object
Read more comments on GitHub >

github_iconTop Results From Across the Web

awk not parsing the first line of file - Stack Overflow
The first line is not comma separated so it is ignored in the sense that the awk command isn't being applied. – antimuon....
Read more >
Parsing Text with PowerShell (1/3) - Microsoft Developer Blogs
A task that appears regularly in my workflow is text parsing. It may be about getting a token from a single line of...
Read more >
pandas.read_table — pandas 1.5.2 documentation
Lines with too many fields (e.g. a csv line with too many commas) will by default cause an exception to be raised, and...
Read more >
How to Parse a CSV File in Bash? - Shell Tips!
Learn how to parse a CSV file in Bash and avoid the common pitfalls. Includes examples using bash builtins and the awk command...
Read more >
Bash Read Comma Separated CSV File on Linux / Unix
IFS variable will set cvs separated to , (comma). The read command will read each line and store data into each field. Let...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found