Skip to content

Commit

Permalink
BUG: Comment in ODS-file gets included in string cells (#55727)
Browse files Browse the repository at this point in the history
* BUG: Comment in ODS-file gets included in string cells

* test if cell is empty and contains annotation
  • Loading branch information
dimastbk authored Oct 30, 2023
1 parent ceee19b commit cb0a11e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 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 @@ -392,6 +392,7 @@ I/O
- Bug in :func:`read_excel`, with ``engine="xlrd"`` (``xls`` files) erroring when file contains NaNs/Infs (:issue:`54564`)
- Bug in :func:`to_excel`, with ``OdsWriter`` (``ods`` files) writing boolean/string value (:issue:`54994`)
- Bug in :meth:`DataFrame.to_hdf` and :func:`read_hdf` with ``datetime64`` dtypes with non-nanosecond resolution failing to round-trip correctly (:issue:`55622`)
- Bug in :meth:`pandas.read_excel` with ``engine="odf"`` (``ods`` files) when string contains annotation (:issue:`55200`)
- Bug in :meth:`pandas.read_excel` with an ODS file without cached formatted cell for float values (:issue:`55219`)
- Bug where :meth:`DataFrame.to_json` would raise an ``OverflowError`` instead of a ``TypeError`` with unsupported NumPy types (:issue:`55403`)
-
Expand Down
4 changes: 4 additions & 0 deletions pandas/io/excel/_odfreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,10 @@ def _get_cell_string_value(self, cell) -> str:
"""
from odf.element import Element
from odf.namespaces import TEXTNS
from odf.office import Annotation
from odf.text import S

office_annotation = Annotation().qname
text_s = S().qname

value = []
Expand All @@ -239,6 +241,8 @@ def _get_cell_string_value(self, cell) -> str:
if fragment.qname == text_s:
spaces = int(fragment.attributes.get((TEXTNS, "c"), 1))
value.append(" " * spaces)
elif fragment.qname == office_annotation:
continue
else:
# recursive impl needed in case of nested fragments
# with multiple spaces
Expand Down
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 @@ -59,3 +59,14 @@ def test_read_unempty_cells():
result = pd.read_excel("test_unempty_cells.ods")

tm.assert_frame_equal(result, expected)


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

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

tm.assert_frame_equal(result, expected)

0 comments on commit cb0a11e

Please sign in to comment.