Skip to content

Commit

Permalink
Added error checking for max Excel rows, and raised exception when th…
Browse files Browse the repository at this point in the history
…e max rows are exceeded for Excel
  • Loading branch information
banflam committed Jan 24, 2025
1 parent 1993d59 commit 2722454
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions py-polars/polars/dataframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
from polars.dependencies import pandas as pd
from polars.dependencies import pyarrow as pa
from polars.exceptions import (
InvalidOperationError,
ColumnNotFoundError,
ModuleUpgradeRequiredError,
NoRowsReturnedError,
Expand Down Expand Up @@ -3505,6 +3506,11 @@ def write_excel(
+ int(bool(column_totals)),
table_start[1] + len(df.columns) - 1,
)

excel_max_valid_rows = 1048575
if len(self.rows) > 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:
Expand Down

0 comments on commit 2722454

Please sign in to comment.