ofajardo/pyreadr

Fails to export data to R

pablodegrande opened this issue · 1 comments

I am using the library to convert an SPSS file, and conversion fails. I am attaching the file....

test.py

import pandas as pd
import pyreadr

df = pd.read_spss('en.sav')
pyreadr.write_rdata('en.rdata', df, df_name="dataset")

Traceback (most recent call last):
File "D:\Pablo\Sociologia\Mapa Social\poblaciones\services\py\test.py", line 5, in
pyreadr.write_rdata('en.rdata', df, df_name="dataset")
File "C:\Python38\lib\site-packages\pyreadr\pyreadr.py", line 119, in write_rdata
writer.write_r(path, file_format, df, df_name, dateformat, datetimeformat)
File "C:\Python38\lib\site-packages\pyreadr_pyreadr_writer.py", line 177, in write_r
pyreadr_types, hasmissing = get_pyreadr_column_types(df)
File "C:\Python38\lib\site-packages\pyreadr_pyreadr_writer.py", line 72, in get_pyreadr_column_types
curtype = type(col[0])
File "C:\Python38\lib\site-packages\pandas\core\series.py", line 882, in getitem
return self._get_value(key)
File "C:\Python38\lib\site-packages\pandas\core\series.py", line 991, in _get_value
loc = self.index.get_loc(label)
File "C:\Python38\lib\site-packages\pandas\core\indexes\base.py", line 2891, in get_loc
raise KeyError(key) from err
KeyError: 0

en.zip

thanks for the reproducible example!
issue solved in pyreadr 0.3.1, now ready in pypi and soon availabe in conda forge.