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: manage raw ods file without cell cache #55219

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)