Skip to content

Commit cb0a11e

Browse files
authored
BUG: Comment in ODS-file gets included in string cells (#55727)
* BUG: Comment in ODS-file gets included in string cells * test if cell is empty and contains annotation
1 parent ceee19b commit cb0a11e

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ I/O
392392
- Bug in :func:`read_excel`, with ``engine="xlrd"`` (``xls`` files) erroring when file contains NaNs/Infs (:issue:`54564`)
393393
- Bug in :func:`to_excel`, with ``OdsWriter`` (``ods`` files) writing boolean/string value (:issue:`54994`)
394394
- Bug in :meth:`DataFrame.to_hdf` and :func:`read_hdf` with ``datetime64`` dtypes with non-nanosecond resolution failing to round-trip correctly (:issue:`55622`)
395+
- Bug in :meth:`pandas.read_excel` with ``engine="odf"`` (``ods`` files) when string contains annotation (:issue:`55200`)
395396
- Bug in :meth:`pandas.read_excel` with an ODS file without cached formatted cell for float values (:issue:`55219`)
396397
- Bug where :meth:`DataFrame.to_json` would raise an ``OverflowError`` instead of a ``TypeError`` with unsupported NumPy types (:issue:`55403`)
397398
-

pandas/io/excel/_odfreader.py

+4
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ def _get_cell_string_value(self, cell) -> str:
228228
"""
229229
from odf.element import Element
230230
from odf.namespaces import TEXTNS
231+
from odf.office import Annotation
231232
from odf.text import S
232233

234+
office_annotation = Annotation().qname
233235
text_s = S().qname
234236

235237
value = []
@@ -239,6 +241,8 @@ def _get_cell_string_value(self, cell) -> str:
239241
if fragment.qname == text_s:
240242
spaces = int(fragment.attributes.get((TEXTNS, "c"), 1))
241243
value.append(" " * spaces)
244+
elif fragment.qname == office_annotation:
245+
continue
242246
else:
243247
# recursive impl needed in case of nested fragments
244248
# with multiple spaces
Binary file not shown.

pandas/tests/io/excel/test_odf.py

+11
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,14 @@ def test_read_unempty_cells():
5959
result = pd.read_excel("test_unempty_cells.ods")
6060

6161
tm.assert_frame_equal(result, expected)
62+
63+
64+
def test_read_cell_annotation():
65+
expected = pd.DataFrame(
66+
["test", np.nan, "test 3"],
67+
columns=["Column 1"],
68+
)
69+
70+
result = pd.read_excel("test_cell_annotation.ods")
71+
72+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)