-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
EHN: to_csv compression accepts file-like object #21249
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
Changes from 4 commits
43c6c79
00712b5
799596f
6a90205
ebf9d28
8d0c45b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -241,3 +241,24 @@ def test_compression_size(obj, method, compression): | |
getattr(obj, method)(filename, compression=None) | ||
uncompressed = os.path.getsize(filename) | ||
assert uncompressed > compressed | ||
|
||
|
||
@pytest.mark.parametrize('obj', [ | ||
DataFrame(100 * [[0.123456, 0.234567, 0.567567], | ||
[12.32112, 123123.2, 321321.2]], | ||
columns=['X', 'Y', 'Z']), | ||
Series(100 * [0.123456, 0.234567, 0.567567], name='X')]) | ||
@pytest.mark.parametrize('method', ['to_csv']) | ||
def test_compression_size_fh(obj, method, compression): | ||
if not compression: | ||
pytest.skip("only test compression case.") | ||
|
||
with tm.ensure_clean() as filename: | ||
with open(filename, 'w') as fh: | ||
getattr(obj, method)(fh, compression=compression) | ||
compressed = os.path.getsize(filename) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you asssert that the fh is still open (inside the with block)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 not sure how to do it here. with compression, the original handle is first written and closed and then compressed handle is created in the same name with entirety of strings of original handle enclosed. so assert fh.closed will pass inside the with block at the moment. |
||
with tm.ensure_clean() as filename: | ||
with open(filename, 'w') as fh: | ||
getattr(obj, method)(fh, compression=None) | ||
uncompressed = os.path.getsize(filename) | ||
assert uncompressed > compressed |
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.
can you make a new fixture alongside the existing to just have the compression options (exclude None), e.g. maybe compression_only (and can change the above test to use as well)
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 sure.