Skip to content

Commit 8371d18

Browse files
authored
BUG: manage raw ods file without cell cache (#55219)
* BUG: manage raw ods file without cell cache * fixup! BUG: manage raw ods file without cell cache
1 parent c4efa92 commit 8371d18

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ Bug fixes
223223
- Bug in :class:`AbstractHolidayCalendar` where timezone data was not propagated when computing holiday observances (:issue:`54580`)
224224
- Bug in :class:`pandas.core.window.Rolling` where duplicate datetimelike indexes are treated as consecutive rather than equal with ``closed='left'`` and ``closed='neither'`` (:issue:`20712`)
225225
- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`)
226+
- Bug in :meth:`pandas.read_excel` with a ODS file without cached formatted cell for float values (:issue:`55219`)
226227

227228
Categorical
228229
^^^^^^^^^^^

pandas/io/excel/_odfreader.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def get_sheet_data(
150150
max_row_len = len(table_row)
151151

152152
row_repeat = self._get_row_repeat(sheet_row)
153-
if self._is_empty_row(sheet_row):
153+
if len(table_row) == 0:
154154
empty_rows += row_repeat
155155
else:
156156
# add blank rows to our table
@@ -182,16 +182,6 @@ def _get_column_repeat(self, cell) -> int:
182182

183183
return int(cell.attributes.get((TABLENS, "number-columns-repeated"), 1))
184184

185-
def _is_empty_row(self, row) -> bool:
186-
"""
187-
Helper function to find empty rows
188-
"""
189-
for column in row.childNodes:
190-
if len(column.childNodes) > 0:
191-
return False
192-
193-
return True
194-
195185
def _get_cell_value(self, cell) -> Scalar | NaTType:
196186
from odf.namespaces import OFFICENS
197187

Binary file not shown.

pandas/tests/io/excel/test_odf.py

+11
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,14 @@ def test_read_newlines_between_xml_elements_table():
4848
result = pd.read_excel("test_newlines.ods")
4949

5050
tm.assert_frame_equal(result, expected)
51+
52+
53+
def test_read_unempty_cells():
54+
expected = pd.DataFrame(
55+
[1, np.nan, 3, np.nan, 5],
56+
columns=["Column 1"],
57+
)
58+
59+
result = pd.read_excel("test_unempty_cells.ods")
60+
61+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)