-
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
Update Chart.transform_filter()
to mirror alt.when()
#3657
Comments
I think I support this request, but to be sure with an example:
import altair as alt
from altair import datum
from vega_datasets import data
pop = data.population.url
alt.Chart(pop).mark_area().encode(
x='age:O',
y='people:Q',
).transform_filter(
(datum.year == 2000) & (datum.sex == 1)
)
import altair as alt
from vega_datasets import data
source = data.population.url
alt.Chart(source).mark_area().encode(
x='age:O',
y='people:Q',
).transform_filter(
alt.when(year=2000, sex=1)
) |
Thanks for the quick response @mattijn Apologies, I wrote this up yesterday in a bit of a rush. To clarify, below I've rewritten your comment with what I intended: Current (first example on transform/filter)import altair as alt
from altair import datum
from vega_datasets import data
pop = data.population.url
alt.Chart(pop).mark_area().encode(
x='age:O',
y='people:Q',
).transform_filter(
(datum.year == 2000) & (datum.sex == 1)
) With this feature requestimport altair as alt
from vega_datasets import data
source = data.population.url
alt.Chart(source).mark_area().encode(
x='age:O',
y='people:Q',
).transform_filter(year=2000, sex=1) Alternative (2)Your example corresponds to what I mentioned at the end of the description
import altair as alt
from vega_datasets import data
source = data.population.url
alt.Chart(source).mark_area().encode(
x='age:O',
y='people:Q',
).transform_filter(
alt.when(year=2000, sex=1)
) Expanding on why I prefer not to include
|
Ah, thanks for clarifying. Sounds like a good idea 👍 |
I'm in favor, we're not using the kwargs for anything currently, and using them for direct equality makes sense. |
Experimenting with this now, Early findings
|
Interestingly, this doesn't break any tests, Would indicate what I suspected in (#3657) was true
- Replaces `filter` used as a keyword argument (#3657 (comment)) - Replaces `dict` filters with `FieldOneOfPredicate`
- Builds on the style introdcued for `alt.when` - Shows a few specific kinds of predicates - due to the prior doc listing 5 #3657
What is your suggestion?
The goal is simply to provide equivalent predicate parsing functionality, that is found in
alt.when()
.For example, this would be easy to port over:
I was reading through transform/filter and looking at the implementation:
.transform_filter()
implementationaltair/altair/vegalite/v5/api.py
Lines 2917 to 2924 in 5a6f70d
AFAIK, the signature can be changed without impacting any existing code:
altair/altair/vegalite/v5/api.py
Lines 2888 to 2898 in 5a6f70d
filter
being in**kwargs
empty
condition()
has already been safely updated in this wayI definitely want to do some more testing, but I can't see much that would be blocking closing the gap between the two:
altair/altair/vegalite/v5/api.py
Lines 1214 to 1219 in 5a6f70d
Side note
#695 is referenced on that page, but I think it was resolved a while ago?
Also there are references to
selection()
which was deprecated in5.0.0
Have you considered any alternative solutions?
.transform_filter()
unchangedalt.When
(class) asfilter
When._condition
.transform_filter
withWhen
The text was updated successfully, but these errors were encountered: