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 4 commits into
base: main
Choose a base branch
from

Conversation

banflam
Copy link

@banflam banflam commented Jan 24, 2025

fixes #20870

I have what I believe is a working solution and it is passing all the pre-existing tests. However, I don't know how to test whether my change is creating the expected behavior or not (when the dataframe is too large to be compatible with Excel, an exception should be thrown).

This is my very first commit to an open-source project, so I apologize in advance for any mistakes I might have made and I look forward to hearing any and all feedback.

@github-actions github-actions bot added fix Bug fix python Related to Python Polars labels Jan 24, 2025
Copy link

codecov bot commented Jan 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.77%. Comparing base (7bf42dd) to head (f1ff63f).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20900      +/-   ##
==========================================
+ Coverage   79.76%   79.77%   +0.01%     
==========================================
  Files        1569     1569              
  Lines      222895   222911      +16     
  Branches     2573     2577       +4     
==========================================
+ Hits       177782   177827      +45     
+ Misses      44521    44492      -29     
  Partials      592      592              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@alexander-beedie alexander-beedie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to contribute!
A couple of notes:

  1. You need to account for the headers, which will also write a row, not just the data (so we will write +1 rows when include_headers is True).
  2. The table can start from a cell other than A1, so you also need to account for a starting offset (see the position parameter).
  3. While we're at it we should probably also check the max width too; Excel's max there is 16384 columns 🤔

…cal offset given in the form of an int tuple only], and checked to ensure max Excel cols are also not exceeded
@banflam
Copy link
Author

banflam commented Jan 25, 2025

Thank you for your feedback and guidance. I've made the changes.

With respect to the second point, it appears that position can be either a tuple representing the numerical offset from the first Excel cell, or a string representing the starting cell directly. I have accounted for the tuple but I'm not entirely sure how to parse the string to get an offset. Please let me know what to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

write_excel writes empty file if >1M rows
2 participants