BUG: Was trying to read an ods file and ran into UnboundLocalError in odfreader.py
See original GitHub issue-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
for file in os.listdir('data'): pandas.read_excel(pathlib.Path('data', file), engine='odf')
Sorry I don’t have a minimal data example at this time.
Problem description
Was trying to test pandas reading a collection of ods files and ran into this error.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/michael/.local/share/virtualenvs/merge-csv-NFbvYFrS/lib/python3.8/site-packages/pandas/util/_decorators.py", line 296, in wrapper
return func(*args, **kwargs)
File "/home/michael/.local/share/virtualenvs/merge-csv-NFbvYFrS/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 311, in read_excel
return io.parse(
File "/home/michael/.local/share/virtualenvs/merge-csv-NFbvYFrS/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 906, in parse
return self._reader.parse(
File "/home/michael/.local/share/virtualenvs/merge-csv-NFbvYFrS/lib/python3.8/site-packages/pandas/io/excel/_base.py", line 443, in parse
data = self.get_sheet_data(sheet, convert_float)
File "/home/michael/.local/share/virtualenvs/merge-csv-NFbvYFrS/lib/python3.8/site-packages/pandas/io/excel/_odfreader.py", line 91, in get_sheet_data
value = self._get_cell_value(sheet_cell, convert_float)
File "/home/michael/.local/share/virtualenvs/merge-csv-NFbvYFrS/lib/python3.8/site-packages/pandas/io/excel/_odfreader.py", line 175, in _get_cell_value
return self._get_cell_string_value(cell)
File "/home/michael/.local/share/virtualenvs/merge-csv-NFbvYFrS/lib/python3.8/site-packages/pandas/io/excel/_odfreader.py", line 211, in _get_cell_string_value
value.append(" " * spaces)
UnboundLocalError: local variable 'spaces' referenced before assignment
I took a look at the code in question and it seems like the line may be on the wrong indent level?
Expected Output
The usual dataframes 👍
Output of pd.show_versions()
INSTALLED VERSIONS
commit : d9fff2792bf16178d4e450fe7384244e50635733 python : 3.8.2.final.0 python-bits : 64 OS : Linux OS-release : 5.4.0-42-generic Version : #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 machine : x86_64 processor : x86_64 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8
pandas : 1.1.0 numpy : 1.19.1 pytz : 2020.1 dateutil : 2.8.1 pip : 20.0.2 setuptools : 44.0.0 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : 1.0.1 pymysql : None psycopg2 : None jinja2 : None IPython : None pandas_datareader: None bs4 : None bottleneck : None fsspec : None fastparquet : None gcsfs : None matplotlib : None numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pytables : None pyxlsb : None s3fs : None scipy : None sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None numba : None
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
find a minimal .ods file here that has one column with a header and one data-cell with content
Test (1)
that causes the fail. Put the .ods in the same directory where you run the following python3 snippet:I think, the fail is related to the type of the data-cell where
fragment.qname
is reported as('urn:oasis:names:tc:opendocument:xmlns:text:1.0', 'span')
. As it is not handled by the if-clause,spaces
is not set andvalue.append(" " * spaces)
throws the error. Fixing the indent would solve the problem, but leave thespan
-clause unimplemented.I could not reproduce creating a cell of type
span
in LibreOffice.Sorry for linking to the .ods file but I was not able to upload it here as .ods is not a supported file type
Upgraded pandas to 1.1.3 and ran the program again.
No UnboundLocalError, so it seems to be working again.
thanks for the update.
On Wed, Oct 7, 2020 at 7:21 AM Asish Mahapatra notifications@github.com wrote: