-
Notifications
You must be signed in to change notification settings - Fork 111
feat: add cols_label_with() method
#626
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
Open
jrycw
wants to merge
15
commits into
posit-dev:main
Choose a base branch
from
jrycw:cols-label-with
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d53ae18
Implement `cols_label_with()`
jrycw 43766cc
Add tests for `cols_label_with()`
jrycw f89e19b
Include `cols_label_with()` in `_quarto.yml`
jrycw 22d93b1
Extract unit handling logic for column labels into `_handle_units_syn…
jrycw ee637b8
Add tests for `_handle_units_syntax()`
jrycw 2852f26
Switch the positions of `columns=` and `fn=` parameters in `cols_labe…
jrycw 1ae6f8a
Add `fn=` parameter to `cols_label()`
jrycw 2ee205a
Update type hint for `fn=` in `cols_label()`
jrycw a060849
Revert "Add `fn=` parameter to `cols_label()`
jrycw 73c08f9
Avoid automatic unit syntax handling in `cols_label_with()`
jrycw b3564d2
Allow passing a Polars expression to `converter=` in `cols_label_with()`
jrycw 1d4b4e6
Update the example for `cols_label_with()`
jrycw 25e661c
Add a test for `cols_label_with()` to ensure column order does not af…
jrycw 50542f8
Support passing a list of Polars expressions to `converter=` in `cols…
jrycw ce5d5f1
Simplify `test_handle_units_syntax()`
jrycw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
From pairing w/ Rich, @jrycw WDYT of switching the order of the parameters, so
columnsis beforefn?Looking through the
cols_*()methods in the R library, column selection usually comes first. In the case ofcols_align()where it doesn't, it sounds like it's a historical artifact. Keeping column first might help cement a pattern forcols_*()methods.It makes sense you put it first in the PR, since it doesn't have a default. WDYT of us setting it to
fn = None, and then erroring if fn is 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.
@machow, nice suggestion! I definitely like your idea of introducing
fn=tocols_label()using Polars syntax.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 to @machow for the comment! I think this is a good opportunity to introduce
fn=to accept a callable incols_label()as well.By the way, I noticed that we have two test files for boxhead,
test_boxhead.pyandtest__boxhead.py. I picked one to add the new test, but perhaps we should consider consolidating them in the future.Uh oh!
There was an error while loading. Please reload this page.
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.
As a side note, we might consider using the pl.Expr.name attribute to handle Polars syntax. For example:
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.
Well, I've attempted to implement this in the latest commit. I admit it's a bit of a bold move, so feel free to set it aside for now.
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.
Here’s a simple example:
Uh oh!
There was an error while loading. Please reload this page.
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.
When passing a list of Polars expressions, if a column is referenced multiple times, we can either superimpose the transformations or follow a "last one wins" approach (current implementation).
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 experimenting with this. If it's okay with you, I think we need a little bit more time to chew on this approach / run it past some folks, since it's a bit cutting edge in terms of external libraries using Polars selectors. I definitely think it'll be useful to figure out in the long run though