Repository navigation
Fix CSV Parsing of Quoted Fields, Escaped Quotes, Embedded Delimiters, and Multi-Line Records - #5080
Merged
Merged
Conversation
Signed-off-by: Shreyas Khandekar <[email protected]>
This adds tests for columns delimters in quoted strings and escaped quotes Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
…ine fields; add tests for edge cases Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
Replace with normal cast Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
Enhance CSV reading by optimizing handling of quoted fields and adding fast path for single-line records Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
ShreyasKhandekar
marked this pull request as ready for review
November 21, 2025 19:51
Signed-off-by: Shreyas Khandekar <[email protected]>
…tection and streamline readCSVRecord Signed-off-by: Shreyas Khandekar <[email protected]>
jabraham17
reviewed
Nov 21, 2025
Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
ajpotts
approved these changes
Nov 26, 2025
ajpotts
left a comment
Contributor
There was a problem hiding this comment.
This is great! Love all the tests.
And reflow for readability Signed-off-by: Shreyas Khandekar <[email protected]>
Signed-off-by: Shreyas Khandekar <[email protected]>
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.
Brief
This PR introduces a substantial improvement to Arkouda’s CSV parsing logic, bringing it closer to full RFC 4180 compatibility. Specifically, this PR fixes incorrect handling of:
"") inside fields and headers,These changes address multiple long-standing issues in Arkouda’s CSV reader and enable correct behavior for real-world CSV files.
Fixes:
readcsvdoes not handle escaped quotes correctly #3945readcsvdoes not correctly handle multi-line records in CSV files #5082Overview of the Fixes
1. Correct handling of delimiters inside quoted strings
Arkouda previously treated any delimiter (e.g.,
,) as a field separator—even when it appeared inside a quoted field. This PR rewrites the low-level delimiter scanning logic so that:This ensures correct behavior for fields such as:
2. Proper parsing of escaped quotes (
"")RFC 4180 requires that "" inside a quoted field be interpreted as a literal ".
This PR adds correct recognition of escaped quotes and rewrites them appropriately during parsing.
For example:
now parses to:
3. Support for multi-line records inside quoted fields
Arkouda previously treated physical newlines as record terminators regardless of quoting state. This PR:
Important
#5083 is still left unresolved by this PR.
Example now works correctly:
Tests Added / Updated
This PR adds several targeted tests to cover CSV edge cases that were previously unsupported.
xfailtest for Arkouda does not correctly handle CSV column headers that contain escaped quotes #5083Remaining Work / Future Improvements
While this PR significantly improves compliance and correctness, future enhancements may include:
Performance
The performance is mixed bag unfortunately. As mentioned in the issues related to this PR, there is a challenge to maintain correctness without sacrificing performance. Advancing through the column delimiter in Chapel is fast and efficient, but when we try to take into account maintain the "state" of being in quotes and managing them to ignore column delimiters makes this slower.
This becomes even slower when escaped quotes can exist which require marking and reverting the file pointer to manage reads.
I have added many "fast paths" where if we can determine that there are no quotes, or no multi line fields, we can be less careful and avoid doing some expensive operations. In one of the steps we also have the option to completely revert to the old implementation if we can determine that there are no quotes at all in the entire CSV file.
All the performance numbers here are collected by running:
I have removed the write performance from the output for brevity
1. Here is what the performance looks like for the implementation in the PR:
2. What happens if you remove the "revert back to old implementation" fast path"?
If you remove that fast path, you can argue it more accurately demonstrates the performance of the new implementation. While this is partly true, the new implementation still has a few "fast paths" for when there are some quotes in the file, but not perhaps on every line.
Nevertheless, since it does represent the performance of just the new implementation (which is worse) I have included it here:
3. Compared to performance on main
So in general, performance is Much better for string reads (close to
7xbetter), but worse for typed reads (about1.5xworse).Most CSV files are all "string reads" in Arkouda because if Arkouda doesn't see the type headers (only available if arkouda wrote the csv file), then all the reads are string reads.
Given the above, this should improve performance in all cases when reading a CSV file written by some other tool.
If you're writing to CSV from Arkouda and reading it back, and you care about performance, then you should be using parquet anyway.
Summary
This PR fixes several major issues with Arkouda's CSV parsing:
These improvements bring Arkouda's CSV behavior more in line with RFC 4180 and with tools such as Pandas, enabling more reliable ingestion of real-world CSV datasets.