Skip to content

Commit

Permalink
BUG: Infer compression by default in read_fwf() (pandas-dev#22199)
Browse files Browse the repository at this point in the history
  • Loading branch information
NasaGeek committed Nov 4, 2018
1 parent d78bd7a commit b0c6c4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pandas/io/parsers.py
Expand Up @@ -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)
Expand Down
20 changes: 11 additions & 9 deletions pandas/tests/io/parser/test_read_fwf.py
Expand Up @@ -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 = """
Expand Down

0 comments on commit b0c6c4a

Please sign in to comment.