Skip to content
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

Merged
merged 7 commits into from
Mar 26, 2023

Conversation

joelostblom
Copy link
Contributor

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.

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."
Copy link
Contributor

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.

Copy link
Contributor Author

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 and if_false values of a condition. One of the them has to specify a value or datum definition.

Copy link
Contributor

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

altair/vegalite/v5/api.py Outdated Show resolved Hide resolved
tests/utils/test_schemapi.py Outdated Show resolved Hide resolved
Co-authored-by: Mattijn van Hoek <mattijn@gmail.com>
@joelostblom joelostblom merged commit b27b829 into master Mar 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unhelpful error message when a field is incorrectly used as the outer else value in a condition
2 participants