Conversation
parse() only flushed the pending value when the current row already had an entry, which a one-column row never has until its newline. The last row was dropped, a single-value file parsed to no rows, and loadTable() then threw reading data[0].length. Flush whenever the parser is in the middle of a value, and give an empty file an empty table. Resolves processing#9222
1 of 19 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #9222
Changes:
src/io/csv.js: at the end of input, the parser now flushes the pending value whenever it's partway through a value (state !== 0), not only when the row already has an entry. So one-column rows keep their last value, and a file holding a single value parses to one row. A trailing newline still ends in state 0 with an empty entry, so no phantom row is added.src/io/files.js:loadTable()builds an empty table from an empty file instead of readingdata[0].lengthon no rows. Withheader, the columns fall back to[]instead ofundefined, as suggested in the issue.test/unit/io/csv.js(new):parse()tests for:Four of them fail on
main.test/unit/io/loadTable.js: threeloadTable()tests with new assets (one-column file, single value, empty file).parse()before and after:"a\nb"[["a"]][["a"],["b"]]"only","42"[][["only"]],[["42"]]"\"only\""[][["only"]]"a\n\nb"[["a"],[""]][["a"],[""],["b"]]"a\n","x,y\n1,2","x,",""npx vitest run --project unit-tests test/unit/io/csv.js test/unit/io/loadTable.js: 19 passed.PR Checklist
npm run lintpasses