Description
Code Sample, a copy-pastable example if possible
import pandas as pd
pd.read_sas('/tmp/foo')
Output (/tmp/foo
does not have to exist):
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-10-de3f5c15fb71> in <module>
1 import pandas as pd
----> 2 pd.read_sas('/tmp/foo')
~/.virtualenvs/pandas/lib/python3.7/site-packages/pandas/io/sas/sasreader.py in read_sas(filepath_or_buffer, format, index, encoding, chunksize, iterator)
50 pass
51
---> 52 if format.lower() == 'xport':
53 from pandas.io.sas.sas_xport import XportReader
54 reader = XportReader(filepath_or_buffer, index=index,
AttributeError: 'NoneType' object has no attribute 'lower'
Problem description
When format=None
the function attempts to infer the file's format by naively looking at the extension. If it is neither '.xpt'
nor '.sas7bdat'
then an error is raised. However, this logic is wrapped in a try/except block that catches the raised error and silently discards it:
pandas/pandas/io/sas/sasreader.py
Lines 35 to 53 in 179822a
The function then attempts to call format.lower()
but format
is still None
so an AttributeError
is raised.
Expected Output
Expected behaviour: error raised when unable to infer format. Suggest documenting that inference is done by checking the file's extension.
ValueError: unable to infer format of SAS file
Output of pd.show_versions()
[paste the output of pd.show_versions()
here below this line]
INSTALLED VERSIONS
commit: None
python: 3.7.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.19.12-arch1-1-ARCH
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8
LOCALE: en_GB.UTF-8
pandas: 0.23.4
pytest: None
pip: 18.1
setuptools: 40.6.3
Cython: None
numpy: 1.15.4
scipy: None
pyarrow: None
xarray: None
IPython: 7.2.0
sphinx: None
patsy: None
dateutil: 2.7.5
pytz: 2018.7
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