-
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
Display more helpful error message when two fields strings are used in condition #2979
Conversation
altair/vegalite/v5/api.py
Outdated
if_true.update(kwargs) | ||
if isinstance(if_false, str): | ||
raise ValueError( | ||
"A field cannot be used in both the `if_true` and `if_false` branches of a condition. One of the them has to specify a `value` or `datum` definition." |
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.
branches of a condition
is this the correct way to describe this? I've never heard of this before.
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.
I was hesitant about writing it like that too, but went with it because the VegaLite docs use something similar"
When using a conditional field definition, only value or datum may be specified as the else (outer) branch.
Do you think changing the error message to the following would be clearer?
A field cannot be used as both the
if_true
andif_false
values of a condition. One of the them has to specify avalue
ordatum
definition.
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.
Yes, I think that's better (single them).
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.
Updated!
bf183e2
to
50c12f7
Compare
Co-authored-by: Mattijn van Hoek <mattijn@gmail.com>
This is an attempt to resolve #2935.
If there are other string that can be passed to conditions that are not references for fields, then that would be an issue for this PR, but I can't think of any on the top of my head. It could also be argued that maybe this should be fixed in VegaLite, but it seems helpful and straightforward to fix it directly in Altair.