diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index cd9d3ccb79af84..4acd302de3eccf 100755 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -427,7 +427,7 @@ def _read(filepath_or_buffer, kwds): encoding = re.sub('_', '-', encoding).lower() kwds['encoding'] = encoding - compression = kwds.get('compression') + compression = kwds.get('compression', 'infer') compression = _infer_compression(filepath_or_buffer, compression) filepath_or_buffer, _, compression, should_close = get_filepath_or_buffer( filepath_or_buffer, encoding, compression) diff --git a/pandas/tests/io/parser/test_read_fwf.py b/pandas/tests/io/parser/test_read_fwf.py index f7846f7824ba50..2ae60766a5295b 100644 --- a/pandas/tests/io/parser/test_read_fwf.py +++ b/pandas/tests/io/parser/test_read_fwf.py @@ -206,15 +206,17 @@ def test_fwf_compression(self): expected = read_fwf(StringIO(data), widths=widths, names=names) if compat.PY3: data = bytes(data, encoding='utf-8') - comps = [('gzip', gzip.GzipFile), ('bz2', bz2.BZ2File)] - for comp_name, compresser in comps: - with tm.ensure_clean() as path: - tmp = compresser(path, mode='wb') - tmp.write(data) - tmp.close() - result = read_fwf(path, widths=widths, names=names, - compression=comp_name) - tm.assert_frame_equal(result, expected) + comps = [('gzip', 'gz', gzip.GzipFile), ('bz2', 'bz2', bz2.BZ2File)] + for comp_name, extension, compresser in comps: + for kwargs in [ + {'compression': comp_name}, {'compression': 'infer'}, {}]: + with tm.ensure_clean(filename='tmp.%s' % extension) as path: + tmp = compresser(path, mode='wb') + tmp.write(data) + tmp.close() + result = read_fwf(path, widths=widths, names=names, + **kwargs) + tm.assert_frame_equal(result, expected) def test_comment_fwf(self): data = """