Skip to content
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

BUG: Read SAS fails #12659

Closed
gdementen opened this issue Mar 17, 2016 · 2 comments
Closed

BUG: Read SAS fails #12659

gdementen opened this issue Mar 17, 2016 · 2 comments
Labels
Bug IO SAS SAS: read_sas
Milestone

Comments

@gdementen
Copy link
Contributor

cc: @kshedden

Code Sample, a copy-pastable example if possible

https://github.com/pydata/pandas/blob/8857008178eb90b59ca67874507ef860b3faf88f/pandas/io/tests/sas/data/test17.sas7bdat

Do you want a PR with this test case?

Expected Output

pandas reads the file without crashing :)
I tracked the problem to _process_columntext_subheader. It seems like there is an encoding issue...

You might need to apply PR #12658 first to see this issue.

FWIW, here is an AWFUL HACK to make pandas read the file "almost" correctly (I get column names as bytes instead of str in this case).

@@ -524,17 +524,17 @@ class SAS7BDATReader(BaseIterator):

         offset += self._int_length
         text_block_size = self._read_int(offset, _text_block_size_length)

         buf = self._read_bytes(offset, text_block_size)
-        self.column_names_strings.append(
-            buf[0:text_block_size].rstrip(b"\x00 ").decode())
+        self.column_names_strings.append(buf)
         if len(self.column_names_strings) == 1:
             column_name = self.column_names_strings[0]
             compression_literal = ""
             for cl in _compression_literals:
+                cl = bytes(cl, 'ascii')
                 if cl in column_name:
                     compression_literal = cl
             self.compression = compression_literal
             offset -= self._int_length

output of pd.show_versions()

commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None

pandas: 0.18.0
nose: 1.3.7
pip: 8.1.0
setuptools: 20.2.2
Cython: None
numpy: 1.10.4
scipy: None
statsmodels: None
xarray: None
IPython: 4.1.2
sphinx: 1.3.1
patsy: None
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: 1.0.0
tables: 3.2.2
numexpr: 2.4.6
matplotlib: 1.5.1
openpyxl: 2.3.2
xlrd: 0.9.4
xlwt: None
xlsxwriter: 0.8.4
lxml: 3.5.0
bs4: None
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.8
boto: None

@jreback
Copy link
Contributor

jreback commented Mar 17, 2016

cc @kshedden

@abjer
Copy link

abjer commented Mar 23, 2016

I had the same issue on Ubuntu 15.10 running Python 2.7.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO SAS SAS: read_sas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants