Skip to content

Commit 868e671

Browse files
committed
TST: test to_csv infers compression by default
1 parent 65f0689 commit 868e671

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pandas/tests/io/formats/test_to_csv.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3+
import gzip
34
import sys
45

56
import pytest
@@ -351,3 +352,15 @@ def test_to_csv_compression(self, compression_only,
351352
result = pd.read_csv(path, index_col=0,
352353
compression=read_compression)
353354
tm.assert_frame_equal(result, df)
355+
356+
def test_compression_defaults_to_infer(tmpdir):
357+
"""
358+
Test that to_csv defaults to inferring compression from paths.
359+
https://github.com/pandas-dev/pandas/pull/22011
360+
"""
361+
df = DataFrame({"A": [1]})
362+
with tm.ensure_clean('compressed.csv.gz') as path:
363+
df.to_csv(path, index=False)
364+
with gzip.open(path, 'rt') as read_file:
365+
lines = read_file.read().splitlines()
366+
assert lines == ['A', '1']

0 commit comments

Comments
 (0)