Read compressed CSVs - #1217
Read compressed CSVs#1217VisruthSK wants to merge 6 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1217 +/- ##
==========================================
+ Coverage 92.40% 92.43% +0.02%
==========================================
Files 15 15
Lines 6570 6568 -2
==========================================
Hits 6071 6071
+ Misses 499 497 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for keeping this up to date. I haven't had a chance to seriously look at this yet, although I'm still interested in it. Trying to make a push on the compilation/c++ options stuff first |
Use the same gzip/bzip2 -dc | grep pipeline on every platform instead of zgrep/bzgrep on Unix, so the two platform branches share one command builder and no longer depend on the wrapper scripts. Error clearly when the decompression tool is missing rather than failing inside fread(). Only accept .csv, .csv.gz and .csv.bz2 files, not any .gz or .bz2 file. Document the feature in the files argument and NEWS, and extend the test to cover a mixed list and as_cmdstan_fit().
There was a problem hiding this comment.
This looks quite good. I committed a couple of small improvements and the missing doc. But there's one bigger issue we should probably deal with, even though it's probably uncommon. I asked codex about it:
With the current
gzip/bzip2 -dc | grepa truncated or damaged archive can produce part of the CSV before the decompressor fails. grep can still exit successfully, so fread() treats the command as successful and read_cmdstan_csv() returns only the rows it received. I reproduced this with both gzip and bzip2.
Maybe we should run gzip -t or bzip2 -t once per compressed file before reading it? And if that fails then we throw an informative error message (and leave the file unmodified)?
That said, this would add a fourth decompression (metadata, sampler diagnostics, variables, and now this check), which is annoying. But we could probably keep it to three by reading all the requested diagnostic and variable columns once. Something like this (although I haven't checked if there are subtleties I'm overlooking):
selected <- c(sampler_diagnostics, variables)
csv_data <- data.table::fread(cmd = fread_cmd, select = selected, ...)
diagnostics <- csv_data[sampler_diagnostics]
draws <- csv_data[variables]What do you think?
Also, after we merge this we could extend to #1276, which would make this much more convenient. But that should be done separately I think
|
Agree, that approach seems good too to collapse to three reads. I think it makes sense to stack 1276 with this so they are merged together? Or to do 1276 in this PR too. |
|
I think I'd prefer stacking rather than combining, but not super strongly, so whatever you prefer is fine |
This PR was generated by Codex.
Submission Checklist
Summary
Support compressed CSVs. Closes #1027.
Copyright and Licensing
Please list the copyright holder for the work you are submitting
(this will be you or your assignee, such as a university or company):
Visruth Srimath Kandali
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses: