-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
ENH: adding autofilter when writing to excel (pandas-dev#61194) #62994
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
base: main
Are you sure you want to change the base?
Conversation
WillAyd
left a comment
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.
Small comment but overall looks like a really nice PR. @rhshadrach any thoughts?
| Convert 0-based column index to Excel column name. | ||
| """ | ||
| column_name = "" | ||
| while index > 0 or not column_name: |
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.
Can you raise when index < 0? Also, what's the point of this being a while loop?
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.
Ignore my while loop comment - I supposed its so you can build column references like AA, BA, etc...
So makes sense, but still in need of a cleanup here
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.
@WillAyd Thanks for the feedback - input validation added.
pandas/tests/io/excel/test_style.py
Outdated
| ws = wb.active | ||
|
|
||
| assert ws.auto_filter.ref is not None | ||
| print(ws.auto_filter.ref) |
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.
Can you remove the print statement?
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.
Print statement removed - thanks for checking!
WillAyd
left a comment
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.
lgtm - let's see what others think
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.
Agreed this is looking very good. Can you add tests for:
index=True- nonzero startrow / startcol
- A DataFrame with MultiIndex columns (also called a hierarchical columns) with both
merge_cells=Trueandmerge_cells=False.
| startrow: int = 0, | ||
| startcol: int = 0, | ||
| freeze_panes: tuple[int, int] | None = None, | ||
| autofilter_range: str | None = None, |
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.
It seems to me we should be raising an error here if a user specifies autofilter=True and it is not supported with an engine rather than silently ignore the user's specification.
doc/source/whatsnew/v3.0.0.rstfile if fixing a bug or adding a new feature.Description of the change:
Added boolean 'autofilter' optional argument to 'DataFrame.to_excel' function to add automatic filters to all columns in the exported excel files. As discussed with @WillAyd starting simple by allowing to add filters only to all or none columns.
New option supported by 'xlsxwriter' and 'openpyxl' engines.