Skip to content

ERR: better error message on too large excel sheet #26080

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

Merged
merged 17 commits into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 9 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2146,8 +2146,17 @@ def to_excel(self, excel_writer, sheet_name="Sheet1", na_rep="",
index_label=None, startrow=0, startcol=0, engine=None,
merge_cells=True, encoding=None, inf_rep="inf", verbose=True,
freeze_panes=None):

df = self if isinstance(self, ABCDataFrame) else self.to_frame()

excel_max_rows = 2**20
excel_max_cols = 2**14
num_rows, num_cols = df.shape
if num_rows > excel_max_rows or num_cols > excel_max_cols:
raise ValueError("This sheet is too large! Your sheet size is: " +
"{}, {} ".format(num_rows, num_cols) +
"Max sheet size is: {}, {}".format(excel_max_rows, excel_max_cols))

from pandas.io.formats.excel import ExcelFormatter
formatter = ExcelFormatter(df, na_rep=na_rep, cols=columns,
header=header,
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/generic/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,15 @@ def test_pct_change(self, periods, fill_method, limit, exp):
class TestNDFrame(object):
# tests that don't fit elsewhere

def test_to_excel_size(self):
BREAKING_SHAPE = (2**20 + 1, 2**14 + 1)
arr = np.zeros(shape=BREAKING_SHAPE)
df = pd.DataFrame(arr)
filepath = 'test.xlsx'

with pytest.raises(ValueError):
df.to_excel(filepath)

def test_sample(sel):
# Fixes issue: 2419
# additional specific object based tests
Expand Down