Skip to content

Commit

Permalink
BUG: boolean/string value in OdsWriter (#54994)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimastbk committed Sep 4, 2023
1 parent 4b456e2 commit 9dea1cd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 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 @@ -227,6 +227,7 @@ MultiIndex
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`)

Period
^^^^^^
Expand Down
27 changes: 19 additions & 8 deletions pandas/io/excel/_odswriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,15 @@ def _make_table_cell(self, cell) -> tuple[object, Any]:
if isinstance(val, bool):
value = str(val).lower()
pvalue = str(val).upper()
if isinstance(val, datetime.datetime):
return (
pvalue,
TableCell(
valuetype="boolean",
booleanvalue=value,
attributes=attributes,
),
)
elif isinstance(val, datetime.datetime):
# Fast formatting
value = val.isoformat()
# Slow but locale-dependent
Expand All @@ -210,17 +218,20 @@ def _make_table_cell(self, cell) -> tuple[object, Any]:
pvalue,
TableCell(valuetype="date", datevalue=value, attributes=attributes),
)
elif isinstance(val, str):
return (
pvalue,
TableCell(
valuetype="string",
stringvalue=value,
attributes=attributes,
),
)
else:
class_to_cell_type = {
str: "string",
int: "float",
float: "float",
bool: "boolean",
}
return (
pvalue,
TableCell(
valuetype=class_to_cell_type[type(val)],
valuetype="float",
value=value,
attributes=attributes,
),
Expand Down

0 comments on commit 9dea1cd

Please sign in to comment.