-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use compressed CSVs [Resolves #498] #626
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like
DataFrame.to_csv
supports compression.I suppose we can't rely on it to infer compression, because we hand it file descriptors rather than paths, (and they're S3 paths, which it might not consider "path-like") – or, in this case, we hand it
None
, which is very un-path-like. (I'm just guessing that that was the issue you came across.)Regardless, if necessary, it appears that we can invoke it here as:
…But, is the issue that it ignores this when
path is None
?[docs]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Related, is there a reason we don't just do):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pandas doesn't support compression for saving to filehandles with to_csv, only filenames. I found this on a Stackoverflow, which referred to a comment in the pandas source file, which I confirmed by trying it on my own: it 'worked' but the files were the same size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never felt so lied to in my entire life, Pandas 😿
I hope this doesn't risk more memory issues, holding the string temporarily in RAM 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think given how well these matrices compress, the compressed string also existing in RAM (an extra 10% of the original) is not a terrible problem.
Unless you mean the original, uncompressed string (i.e. what we are doing with the None target), which is much worse. I may try and address this in the 'matrix building memory fix' PR that we just talked about and I'm about to start right now, as the main concern there is going to be for memory usage and maybe it'll be worth it to figure out what's needed to bypass
to_csv
and do the saving without extra memory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly 👍
I imagine that even if you can't or don't want to bypass
to_csv
, you can probably tweak it to be RAM-courteous, (even if that meant something terrible likeohio
) 😉There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I mean, you can iterate through the contents like a loop, and just do plain old CSV write. Pandas advertises that they do all these speedups in their to_csv and read_csv, probably involving C, and I'm guessing there's truth to that and my first thought wouldn't be to do that, but maybe it wouldn't be so bad for us (especially given the RAM considerations).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I mean, off the top of my head, it could be a choice between:
a) writing to CSV in Python, outside of Pandas, to something like:
b) trying to hold onto Pandas's utility and ostensible optimizations:
…and the two could be compared for speed, resource usage, complexity.
(For example, though A looks short-and-simple above, and though in B we might lose all of Pandas optimizations by forcing it through our in-Python pipe … in fact, A could be a bit long / sticky in actual implementation, because we're taking over
DataFrame.to_csv
from Pandas.)