-
Notifications
You must be signed in to change notification settings - Fork 794
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
feat: Support Chart.transform_filter(*predicates, **constraints)
#3664
Conversation
Includes deprecation handling
- Need to widen the definition of `_PredicateType` - To support this, we'll need to model with `TypedDict`(s)
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)
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
Thanks @dangotbanned! This looks great! Would it be possible to add the examples that you describe within the docstring of the |
Thanks @mattijn! Yeah that sounds like a good idea, will try and take a look later today |
Thanks @dangotbanned 🥳! |
Will close #3657
Description
This PR enables the same syntax from
alt.when
to 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_when
returns 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
constraints
can simplify compositions like:Tasks
filter
as a keyword argument.transform_filter()
implementation(*predicates, **constraints)
syntax (b497039)dict
typing issue.transform_filter()
docstring (7a0cc42)