Skip to content

Commit

Permalink
BUG: manage raw ods file without cell cache (#55219)
Browse files Browse the repository at this point in the history
* BUG: manage raw ods file without cell cache

* fixup! BUG: manage raw ods file without cell cache
  • Loading branch information
guillett authored Sep 20, 2023
1 parent c4efa92 commit 8371d18
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ Bug fixes
- Bug in :class:`AbstractHolidayCalendar` where timezone data was not propagated when computing holiday observances (:issue:`54580`)
- 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`)
- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`)
- Bug in :meth:`pandas.read_excel` with a ODS file without cached formatted cell for float values (:issue:`55219`)

Categorical
^^^^^^^^^^^
Expand Down
12 changes: 1 addition & 11 deletions pandas/io/excel/_odfreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_sheet_data(
max_row_len = len(table_row)

row_repeat = self._get_row_repeat(sheet_row)
if self._is_empty_row(sheet_row):
if len(table_row) == 0:
empty_rows += row_repeat
else:
# add blank rows to our table
Expand Down Expand Up @@ -182,16 +182,6 @@ def _get_column_repeat(self, cell) -> int:

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

def _is_empty_row(self, row) -> bool:
"""
Helper function to find empty rows
"""
for column in row.childNodes:
if len(column.childNodes) > 0:
return False

return True

def _get_cell_value(self, cell) -> Scalar | NaTType:
from odf.namespaces import OFFICENS

Expand Down
Binary file added pandas/tests/io/data/excel/test_unempty_cells.ods
Binary file not shown.
11 changes: 11 additions & 0 deletions pandas/tests/io/excel/test_odf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,14 @@ def test_read_newlines_between_xml_elements_table():
result = pd.read_excel("test_newlines.ods")

tm.assert_frame_equal(result, expected)


def test_read_unempty_cells():
expected = pd.DataFrame(
[1, np.nan, 3, np.nan, 5],
columns=["Column 1"],
)

result = pd.read_excel("test_unempty_cells.ods")

tm.assert_frame_equal(result, expected)

0 comments on commit 8371d18

Please sign in to comment.