Skip to content

read_fwf() function does not infer compression by default #22199

Closed
@NasaGeek

Description

@NasaGeek

Code Sample, a copy-pastable example if possible

import io
import gzip
import os
import pandas as pd

fwf = b"""a b c\n1 2 3\n4 5 6"""
with gzip.open('file.gz', 'wb') as gz:
    gz.write(fwf)
print(pd.read_fwf('file.gz', compression='infer'))
print(pd.read_fwf('file.gz'))
os.remove('file.gz')

Problem description

The pandas documentation indicates that read_fwf() (as with read_csv()) infers a file's compression type based on its extension by default, but it does not.

Expected Output

I expect 2 identical copies of the dataframe to be displayed.

Output of pd.show_versions()

INSTALLED VERSIONS

commit: 776fed3
python: 3.7.0.final.0
python-bits: 64
OS: Darwin
OS-release: 17.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.0.dev0+418.g776fed3ab
pytest: 3.7.1
pip: 10.0.1
setuptools: 39.0.1
Cython: 0.28.5
numpy: 1.15.0
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: 1.7.6
patsy: None
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugCompatpandas objects compatability with Numpy or Python functionsIO DataIO issues that don't fit into a more specific label

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions