-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(python): Allow passing Callable[[str], bool] to sheet_name parameter of polars.read_excel
#25882
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?
feat(python): Allow passing Callable[[str], bool] to sheet_name parameter of polars.read_excel
#25882
Conversation
…arameter of `polars.read_excel` The `sheet_name` parameter now supports predicate function (`Callable[[str], bool]`) for flexible sheet selection. This is useful when sheet names are generated dynamically (e.g. by date) or when the number of sheets varies between files. This change is fully backward compatible.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #25882 +/- ##
==========================================
- Coverage 80.62% 79.83% -0.80%
==========================================
Files 1765 1763 -2
Lines 243158 242869 -289
Branches 3044 3044
==========================================
- Hits 196055 193885 -2170
- Misses 46321 48203 +1882
+ Partials 782 781 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
alexander-beedie
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.
Lint needs to pass (appears to be failing in the commit tests).
Otherwise this would be fine by me, thanks 👍
| msg = f"cannot specify both `sheet_name` ({sheet_name!r}) and `sheet_id` ({sheet_id!r})" | ||
| raise ValueError(msg) | ||
|
|
||
| if isinstance(sheet_name, Callable): # rewrite sheet_name to a list of names |
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.
Shouldn’t this be
| if isinstance(sheet_name, Callable): # rewrite sheet_name to a list of names | |
| if callable(sheet_name): # rewrite sheet_name to a list of names |
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.
Hi,
I’ve addressed the requested changes.
Thanks and Happy New Year!
|
All requested changes have been addressed. |
What does this PR do?
Adds support for passing a predicate function (
Callable[[str], bool]) to thesheet_nameparameter ofpl.read_excel, allowing flexible sheet selection.Why?
In practice, Excel files often contain sheets with dynamically generated names (e.g. dates) or a variable number of sheets. A predicate-based parameter allows users to select sheets programmatically without relying on
exact string matches.
Changes
sheet_nameto accept a callable predicateBackward compatibility
This change is fully backward compatible. Existing usages of
sheet_name(string, list of strings, etc.) are unaffected.Tests