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

fix(python): Throw exception if dataframe is too large to be compatible with Excel #20900

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
from polars.dependencies import pyarrow as pa
from polars.exceptions import (
ColumnNotFoundError,
InvalidOperationError,
ModuleUpgradeRequiredError,
NoRowsReturnedError,
TooManyRowsReturnedError,
Expand Down Expand Up @@ -3506,6 +3507,11 @@ def write_excel(
table_start[1] + len(df.columns) - 1,
)

excel_max_valid_rows = 1048575
if self.height > excel_max_valid_rows:
msg = "Dataframe too large to be compatible with Excel. Exceeded Excel limit of 1048575 rows of data."
raise InvalidOperationError(msg)

# write table structure and formats into the target sheet
if not is_empty or include_header:
ws.add_table(
Expand Down
Loading