-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Reading a SAS file with 0 rows gives None #18198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
is this just an issue for #18184 ? normally we do open issues first but since u opened the pr we actually don’t need an issue (fyi for the future) |
This is actually an issue for 0 rows and not the 0 variables case. |
When going through this, I realized there may be some confusion in expected behavior. In In [30]: for i, idf in enumerate(pd.read_csv("/tmp/a.csv", iterator=True)):
...: print("IterCount:", i)
...: print(idf)
...:
IterCount: 0
Empty DataFrame
Columns: [a, b, c, d]
Index: [] This seems non-intuitive because even though there are 0 rows, the iterator runs atleast once. While in In [32]: for i, idf in enumerate(pd.read_csv("/tmp/b.csv", iterator=True, chunksize=2)):
...: print("IterCount:", i)
...: print(idf)
...:
IterCount: 0
a b c d
0 1 2 3 4
1 5 6 7 8 This is definitely a bit of a corner case but I'd like to know what is the expected behavior. I believe the following makes sense:
|
Any thoughts on this one ? |
Is this issue still open? Can I pick it up? |
@AbdealiJK this shouldn't be too hard to fix, but in order to test will need a zero-observation sas7bdat file. can you provide one? |
Hi data one_row (compress=no);
char_field = "abc";
num_field = 123.4;
run;
data zero_rows_no_compress (compress=no);
set one_row (obs=0);
run; The above SAS code created the attached SAS file with 0 rows. Hope this helps @jbrockmendel @mukesh5 |
Hi Sorry @jbrockmendel - seems like I missed your ping earlier. |
just in case pyreadstat can read this file OK (if this is what you are expecting):
So one option could be to add pyreadstat as backend for read_sas (it is already used in read_spss). It would also help solving other issues: #37088, #35545, #22720 |
take |
Code Sample, a copy-pastable example if possible
This is
a.csv
: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()
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
The text was updated successfully, but these errors were encountered: