df.write_excel
does not work with file objects
#18849
Labels
A-io-spreadsheet
Area: reading/writing Excel/ODS files
bug
Something isn't working
good first issue
Good for newcomers
P-low
Priority: low
python
Related to Python Polars
Checks
Reproducible example
Log output
Issue description
_xl_setup_workbook
incorrectly defaults to treating file objects likeio.BufferedWriter
,fsspec.implementations.local.LocalFileOpener
, ors3fs.S3File
as paths.This is because the
isinstance(workbook, BytesIO)
condition condition isFalse
for these objects.By contrast,
write_csv
andwrite_json
methods work fine with file-like objects such as the ones mentioned above.Expected behavior
Similar to
write_csv
orwrite_json
, the expected behaviour in_xl_setup_workbook
is to explicitly check that theworkbook
is a string/path-like object, otherwise defaulting to treating theworkbook
as file-like.I think this could be accomplished by modifying the existing if-else statement along the following lines:
Installed versions
The text was updated successfully, but these errors were encountered: