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

Inconsistent Empty File Behavior with read_excel for Calamine #19711

Closed
2 tasks done
max-muoto opened this issue Nov 9, 2024 · 0 comments · Fixed by #19712
Closed
2 tasks done

Inconsistent Empty File Behavior with read_excel for Calamine #19711

max-muoto opened this issue Nov 9, 2024 · 0 comments · Fixed by #19712
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@max-muoto
Copy link
Contributor

max-muoto commented Nov 9, 2024

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

read_excel has inconsistent behavior across Excel engines for raise_if_empty

For empty files, I would expect the schema override not to get applied, and instead get a NoDataError if a schema override is provided for calamine:

# /// script
# dependencies = [
#   "polars[excel]>=1.12.0",
# ]
# ///


import pathlib
import polars as pl


def main() -> None:
    file = pathlib.Path.cwd() / "empty_file.xlsx"
    # Adding a schema override leads to polars.exceptions.ColumnNotFoundError: A
    # Removing it a NoDataError
    df = pl.read_excel(file, engine="calamine", schema_overrides={"A": pl.String})
    print(df)


if __name__ == "__main__":
    main()

(You can reproduce by running this Python script with uv, and creating an empty excel file in the current working directory named empty_file.xlsx)

This behavior differs based on the Excel engine, with openpyxl and xlsx2csv raising a NoDataError for the above code.

Expected behavior

Would expecvt a NoDataError for all engines.

Installed versions

--------Version info---------
Polars:              1.12.0
Index type:          UInt32
Platform:            macOS-14.4.1-arm64-arm-64bit
Python:              3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:12:31) [Clang 14.0.6 ]
LTS CPU:             False

----Optional dependencies----
adbc_driver_manager  <not installed>
altair               <not installed>
cloudpickle          <not installed>
connectorx           <not installed>
deltalake            <not installed>
fastexcel            0.12.0
fsspec               <not installed>
gevent               <not installed>
great_tables         <not installed>
matplotlib           <not installed>
nest_asyncio         <not installed>
numpy                <not installed>
openpyxl             3.1.5
pandas               <not installed>
pyarrow              18.0.0
pydantic             <not installed>
pyiceberg            <not installed>
sqlalchemy           <not installed>
torch                <not installed>
xlsx2csv             0.8.3
xlsxwriter           3.2.0```

</details>
@max-muoto max-muoto added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Nov 9, 2024
@max-muoto max-muoto changed the title Inconsistent Empty File Behavior with read_excel Inconsistent Empty File Behavior with read_excel for Calamine Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant