-
Notifications
You must be signed in to change notification settings - Fork 793
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
The parameter empty
can be used in multiple places which lead to different error messages
#3596
Comments
@joelostblom two points that stood out to me:
|
The code is from this gallery example so select = alt.selection_point(name="select", on="click") Without alt.when(select).then(alt.value(2, nearest=False))
This error makes sense since the
Will try that out later today! |
Previous comment
Okay I think I see the confusion @joelostblom: Reproimport altair as alt
select = alt.selection_point(name="select", on="click")
highlight = alt.selection_point(name="highlight", on="pointerover", empty=False)
stroke_width = (
alt.when(select)
.then(alt.value(2, empty=False))
.when(highlight)
.then(alt.value(1))
.otherwise(alt.value(0))
)
then_nearest_1 = alt.when(select).then(alt.value(2, nearest=False)).to_dict()
# Just testing `alt.value` isn't contributing to the issue
then_nearest_2 = alt.when(select).then(alt.value(2), nearest=False).to_dict()
print(stroke_width, then_nearest_1, then_nearest_2, sep="\n") Output# -------------------------------------------->
{'condition': [{'param': 'select', 'value': 2, 'empty': False}, {'param': 'highlight', 'empty': False, 'value': 1}], 'value': 0}
{'condition': [{'param': 'select', 'value': 2, 'nearest': False}]}
{'condition': [{'param': 'select', 'value': 2, 'nearest': False}]} I had already added links to this page on #3567 but So each element in the list keyed to Code block
class _ConditionClosed(TypedDict, closed=True, total=False): # type: ignore[call-arg]
# https://peps.python.org/pep-0728/
# Parameter {"param", "value", "empty"}
# Predicate {"test", "value"}
empty: Optional[bool]
param: Parameter | str
test: _TestPredicateType
value: Any
_Conditions: TypeAlias = t.List[_ConditionClosed]
"""
Chainable conditions produced by ``.when()`` and ``Then.when()``.
All must be a `Conditional Value`_.
.. _Conditional Value:
https://vega.github.io/vega-lite/docs/condition.html#value
""" |
What happened?
I was playing around with this gallery example when I noticed that there seems to be multiple ways of specifying
empty=True
insidewhen-then-otherwise
. The default in the example is to put it insidealt.value
:However, it also works to put it inside
then()
:and inside
when()
:They all work they same, but somewhat confusingly, the addition of other parameters leads to different behavior between the three. For
when
no error is raised but the parameter is also not applied, e.g.:For the other two, an error is raised, but it points the user in the wrong direction:
What would you like to happen instead?
I think the ideal case would be if we did not allow for
empty
inthen()
and instead only inwhen
which is also clearly documented currently.I don't think there is anything we can do about
value
since it has always acceptedkwds
. But if the error message could be made clearer, then that would be helpful (maybe related to #2913). I think the clearest possible message in the case ofwould be
cc @dangotbanned since you have the most expertise here, do you think it is possible to raise this error instead of the current behavior?
Which version of Altair are you using?
5.4.1
The text was updated successfully, but these errors were encountered: