Reading a SAS file with 0 rows gives None · Issue #18198 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

In [2]: import pandas as pd

In [3]: pd.read_csv("zero_observations.csv") Out[3]: Empty DataFrame Columns: [a, b, c, d] Index: []

In [4]: pd.read_sas("zero_observations.sas7bdat")

In [5]:

This is a.csv:

$ cat zero_observations.csv
a,b,c,d

Problem description

When reading a SAS file with 0 records, it gives None. But when reading a CSV file with 0 records it gives an empty dataframe.

In SAS, we can atleast identify the datatypes correctly and make an empty dataframe with this.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Darwin OS-release: 16.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.21.0
pytest: 3.2.1
pip: 9.0.1
setuptools: 23.0.0
Cython: 0.27.3
numpy: 1.13.3
scipy: 0.18.1
pyarrow: None
xarray: None
IPython: 6.1.0
sphinx: 1.4.9
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.0
openpyxl: None
xlrd: 1.1.0
xlwt: None
xlsxwriter: 0.9.8
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8.1
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None