feat: Support Chart.transform_filter(*predicates, **constraints)#3664
Merged
feat: Support Chart.transform_filter(*predicates, **constraints)#3664
Chart.transform_filter(*predicates, **constraints)#3664Conversation
Includes deprecation handling
- Need to widen the definition of `_PredicateType` - To support this, we'll need to model with `TypedDict`(s)
dangotbanned
commented
Oct 30, 2024
tests/examples_arguments_syntax/line_chart_with_cumsum_faceted.py
Outdated
Show resolved
Hide resolved
This alias may be redundant now, need to review that later
Didn't account for a `TypeError` that can be triggered if `more_predicates` isn't composable.
E.g `filter={"field": "year", "oneOf": [1955, 2000]}`
Chart.transform_filter(*predicates, **constraints)Chart.transform_filter(*predicates, **constraints)
This was referenced Oct 31, 2024
Makes use of #3668 Resolves #3664 (comment)
- Builds on the style introdcued for `alt.when` - Shows a few specific kinds of predicates - due to the prior doc listing 5 #3657
Need to forgo all type safety here, since it would permit `_PredicateType` instead of the narrower `_FieldEqualType`
I added this while trying to resolve a different typing issue, purely to see what was inferred
Think this makes it clearer how each of these align
Contributor
|
Thanks @dangotbanned! This looks great! Would it be possible to add the examples that you describe within the docstring of the |
Member
Author
Thanks @mattijn! Yeah that sounds like a good idea, will try and take a look later today |
Member
Author
Contributor
|
Thanks @dangotbanned 🥳! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Will close #3657
Description
This PR enables the same syntax from
alt.whento be used inalt.TopLevelMixin.transform_filter.Honestly, I'm still a bit shocked by how little needed changing in the implementation.
Besides tweaking the signature and handling the deprecated argument, it really was just these 2 lines:
altair/altair/vegalite/v5/api.py
Lines 3102 to 3103 in 2d57d6e
To explain this,
_parse_whenreturns our version of VL-Condition.We can either use that as-is or unwrap the
"test"key, which stores an already parsed test VL-Predicate.Besides this small change, most of the PR consists of new docs & tests.
Doc (Examples)
Setting up a common chart:
Singular predicates can be expressed via
datum:We can also use selection parameters directly:
Or a field predicate:
Predicates can be composed together using logical operands:
Predicates passed as positional arguments will be reduced with
&:Using keyword-argument
constraintscan simplify compositions like:Tasks
filteras a keyword argument.transform_filter()implementation(*predicates, **constraints)syntax (b497039)dicttyping issue.transform_filter()docstring (7a0cc42)