Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read_excel doesn't accept bytes #20526

Closed
2 tasks done
ReRubis opened this issue Jan 2, 2025 · 3 comments · Fixed by #20636
Closed
2 tasks done

read_excel doesn't accept bytes #20526

ReRubis opened this issue Jan 2, 2025 · 3 comments · Fixed by #20636
Labels
A-io-spreadsheet Area: reading/writing Excel/ODS files accepted Ready for implementation bug Something isn't working good first issue Good for newcomers P-low Priority: low python Related to Python Polars

Comments

@ReRubis
Copy link

ReRubis commented Jan 2, 2025

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

from pathlib import Path

import polars as pl

bytes_data = Path("Untitled.spreadsheet.xlsx").read_bytes()

try:
    pl.read_excel(bytes_data)
except Exception as e:
    print(e)

Log output

source must be a string or bytes

Issue description

When I try to read a certain xlsx files in bytes, pl.read_excel() fails to read it.
Works on 1.17.

Here is an empty xlsx created in google sheets.
Untitled spreadsheet.xlsx

Expected behavior

A dataframe or a message indicating an empty file.

Installed versions

--------Version info---------
Polars:              1.18.0
Index type:          UInt32
Platform:            Linux-6.12.6-arch1-1-x86_64-with-glibc2.36
Python:              3.11.9 (main, Sep  5 2024, 00:16:19) [GCC 12.2.0]
LTS CPU:             False

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
azure.identity       <not installed>
boto3                <not installed>
cloudpickle          3.1.0
connectorx           <not installed>
deltalake            <not installed>
fastexcel            0.12.0
fsspec               <not installed>
gevent               <not installed>
google.auth          2.37.0
great_tables         <not installed>
matplotlib           3.9.4
nest_asyncio         1.6.0
numpy                1.26.4
openpyxl             3.1.5
pandas               2.2.3
pyarrow              18.1.0
pydantic             2.6.4
pyiceberg            <not installed>
sqlalchemy           2.0.36
torch                <not installed>
xlsx2csv             <not installed>
xlsxwriter           3.2.0
@ReRubis ReRubis added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Jan 2, 2025
@DoTheBestToGetTheBest
Copy link

you need to wrap your bytes in BytesIO object

@ReRubis
Copy link
Author

ReRubis commented Jan 6, 2025

you need to wrap your bytes in BytesIO object

I don't . At least according to the typehints.

FileSource: TypeAlias = Union[
    str,
    Path,
    IO[bytes],
    bytes,
    list[str],
    list[Path],
    list[IO[bytes]],
    list[bytes],+
]

UPD: The error message also clearly states that it should be str|bytes.

@nameexhaustion nameexhaustion added good first issue Good for newcomers P-low Priority: low and removed needs triage Awaiting prioritization by a maintainer labels Jan 7, 2025
@github-project-automation github-project-automation bot moved this to Ready in Backlog Jan 7, 2025
@nameexhaustion nameexhaustion added the accepted Ready for implementation label Jan 7, 2025
@alexander-beedie alexander-beedie added the A-io-spreadsheet Area: reading/writing Excel/ODS files label Jan 9, 2025
@github-project-automation github-project-automation bot moved this from Ready to Done in Backlog Jan 9, 2025
@alexander-beedie
Copy link
Collaborator

alexander-beedie commented Jan 9, 2025

I don't . At least according to the type hints.

Indeed, you shouldn't need to; this was an accidental regression which I've just fixed (and added extra test coverage to ensure it doesn't happen again). Fix will be in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io-spreadsheet Area: reading/writing Excel/ODS files accepted Ready for implementation bug Something isn't working good first issue Good for newcomers P-low Priority: low python Related to Python Polars
Projects
Archived in project
4 participants