-
-
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
fix(python): Throw exception if dataframe is too large to be compatible with Excel #20900
Conversation
…e max rows are exceeded for Excel
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20900 +/- ##
==========================================
+ Coverage 79.76% 79.90% +0.14%
==========================================
Files 1569 1597 +28
Lines 222895 229120 +6225
Branches 2573 2619 +46
==========================================
+ Hits 177782 183078 +5296
- Misses 44521 45443 +922
- Partials 592 599 +7 ☔ 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 |
Hi, I'm just following up on this |
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.
Just updated the temporary path in the test (a fixed /tmp/
would fail on Windows, for example, so we have a "tmp_path" fixture that provides something suitable 👍)
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.
Congratulations (and thanks) on your first PR 😎
…le with Excel (pola-rs#20900) Co-authored-by: Alexander Beedie <[email protected]>
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.