-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
base: main
Are you sure you want to change the base?
fix(python): Throw exception if dataframe is too large to be compatible with Excel #20900
Conversation
…e max rows are exceeded for Excel
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #20900 +/- ##
==========================================
- Coverage 79.76% 79.30% -0.46%
==========================================
Files 1569 1578 +9
Lines 222895 224140 +1245
Branches 2573 2575 +2
==========================================
- Hits 177782 177754 -28
- Misses 44521 45794 +1273
Partials 592 592 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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:
- 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). - The table can start from a cell other than A1, so you also need to account for a starting offset (see the
position
parameter). - 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
Thank you for your feedback and guidance. I've made the changes. With respect to the second point, it appears that |
The |
…relies on the table_finish variable
Thanks for that. I've removed the old code and replaced it with code that depends on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff; the new check looks great - let's just tweak the error message when the check fails (done) and add a unit test, then this looks good to go 😎👍
You can add a simple unit test in py-polars/tests/unit/io/test_spreadsheet.py
; try writing a few rows at an extreme offset (say, a 10 row dataset at position "A1048570") to confirm that the expected error is generated (in that file you can see other examples using with pytest.raises
that check specific error conditions).
Thanks for the feedback. I've also written the test you mentioned. I hope that this pull request is now fine to be merged |
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.