df.to_csv ignores compression when provided with a file handle · Issue #21227 · pandas-dev/pandas (original) (raw)

Code at issue

with open(outputfile, "w") as file_handle: df2.to_csv(file_handle, compression='gzip')

Problem description

The written file is not gzip compressed.

Expected Output

The output should be a gzip compressed csv file. Similar to what is obtained when using:

df2.to_csv('/path/to/file.csv.gz',compression='gzip')