Has anyone created a fast and reliable CSV reader for Mathematica? I have been meaning to do this for a while, but did not have the time yet. I thought I would post this as a question in case someone else has already done it (or someone is willing to do it in the near future). It would need to be a LibraryLink-based implementation for good performance.
Desired features:
-
Reliable, no surprises. I have a strong dislike of the current
Importimplementation because surprises like this have messed up my results in the past. -
The ability to explicitly specify data types for each column.
SemanticImporthas this, but it is very slow.Importis much faster, but it detects the type of each element separately, and does not return type-consistent columns. I don’t want mixed data in my columns and I don’t want to import12as12.0when I know that column only has strings. -
Fast. I was watching this Python visualization tutorial that worked with the NYC taxi dataset, and thought that unfortunately Mathematica just can’t do this … the data is too big for it.
-
Memory efficient. Each CSV column should be imported as a separate array. When the data type allows, it should be a packed array.
Datasetwas not memory efficient last time I checked. It stored each row as a mixed-type association. -
Handle header lines (each column has a name)
-
Nice to have, but not required: Handle quoting/strings. In automatic data type detection mode, it should know that
"123"is a string, not a number.
To sum up, I want a CSV reader which trades off some of the flexibility of Import and SemanticImport for performance, memory efficiency and reliability/predictability.
R/Pandas/Julia and now even MATLAB all have this. Why doesn’t Mathematica?
Is there anyone else here who is missing such functionality? More importantly, is there anyone else here who missed it so much that they already implemented it? Perhaps Boost Spirit would be a good starting point.
Or am I mistaken and is it already possible to handle very large CSV or TSV files in a type-consistent, performant and reliable way?