Skip to content

Commit 9dea1cd

Browse files
committed
BUG: boolean/string value in OdsWriter (#54994)
1 parent 4b456e2 commit 9dea1cd

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ MultiIndex
227227
I/O
228228
^^^
229229
- Bug in :func:`read_excel`, with ``engine="xlrd"`` (``xls`` files) erroring when file contains NaNs/Infs (:issue:`54564`)
230+
- Bug in :func:`to_excel`, with ``OdsWriter`` (``ods`` files) writing boolean/string value (:issue:`54994`)
230231

231232
Period
232233
^^^^^^

pandas/io/excel/_odswriter.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,15 @@ def _make_table_cell(self, cell) -> tuple[object, Any]:
192192
if isinstance(val, bool):
193193
value = str(val).lower()
194194
pvalue = str(val).upper()
195-
if isinstance(val, datetime.datetime):
195+
return (
196+
pvalue,
197+
TableCell(
198+
valuetype="boolean",
199+
booleanvalue=value,
200+
attributes=attributes,
201+
),
202+
)
203+
elif isinstance(val, datetime.datetime):
196204
# Fast formatting
197205
value = val.isoformat()
198206
# Slow but locale-dependent
@@ -210,17 +218,20 @@ def _make_table_cell(self, cell) -> tuple[object, Any]:
210218
pvalue,
211219
TableCell(valuetype="date", datevalue=value, attributes=attributes),
212220
)
221+
elif isinstance(val, str):
222+
return (
223+
pvalue,
224+
TableCell(
225+
valuetype="string",
226+
stringvalue=value,
227+
attributes=attributes,
228+
),
229+
)
213230
else:
214-
class_to_cell_type = {
215-
str: "string",
216-
int: "float",
217-
float: "float",
218-
bool: "boolean",
219-
}
220231
return (
221232
pvalue,
222233
TableCell(
223-
valuetype=class_to_cell_type[type(val)],
234+
valuetype="float",
224235
value=value,
225236
attributes=attributes,
226237
),

0 commit comments

Comments
 (0)