Skip to content

Commit 00712b5

Browse files
committed
test filehandle compression for to_csv
1 parent 43c6c79 commit 00712b5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

pandas/tests/test_common.py

+21
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,24 @@ def test_compression_size(obj, method, compression):
241241
getattr(obj, method)(filename, compression=None)
242242
uncompressed = os.path.getsize(filename)
243243
assert uncompressed > compressed
244+
245+
246+
@pytest.mark.parametrize('obj', [
247+
DataFrame(100 * [[0.123456, 0.234567, 0.567567],
248+
[12.32112, 123123.2, 321321.2]],
249+
columns=['X', 'Y', 'Z']),
250+
Series(100 * [0.123456, 0.234567, 0.567567], name='X')])
251+
@pytest.mark.parametrize('method', ['to_csv'])
252+
def test_compression_size_fh(obj, method, compression):
253+
if not compression:
254+
pytest.skip("only test compression case.")
255+
256+
with tm.ensure_clean() as filename:
257+
with open(filename, 'w') as fh:
258+
getattr(obj, method)(fh, compression=compression)
259+
compressed = os.path.getsize(filename)
260+
with tm.ensure_clean() as filename:
261+
with open(filename, 'w') as fh:
262+
getattr(obj, method)(fh, compression=None)
263+
uncompressed = os.path.getsize(filename)
264+
assert uncompressed > compressed

0 commit comments

Comments
 (0)