You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it be useful to have the equivalent of pandas assert_frame_equal for Altair charts? I was drafting a function for this to use when grading student submissions and thought maybe it would be beneficial to have more widely available.
AssertionError: Key mismatch: 'mark.color' was unexpected.
Function draft
This could be extended to e.g. optionally exclude keys from comparisons (such as the data/datasets which should probably be excluded by default).
importaltairasaltdefassert_chart_equal(expected, actual):
expected_dict=expected.to_dict()
actual_dict=actual.to_dict()
assert_dict_equal(expected_dict, actual_dict)
defassert_dict_equal(expected_dict, actual_dict, path=""):
# Check all keys in dict1forkeyinexpected_dict:
ifkeynotinactual_dict:
raiseAssertionError(
f"Key mismatch: '{path+key}' was expected, but not found."
)
else:
# If both values are dictionaries, recurse into themifisinstance(expected_dict[key], dict) andisinstance(
actual_dict[key], dict
):
assert_dict_equal(
expected_dict[key], actual_dict[key], path+key+"."
)
# Compare the valueselifexpected_dict[key] !=actual_dict[key]:
raiseAssertionError(
f"Value mismatch at '{path+key}': {expected_dict[key]} != {actual_dict[key]}"
)
# Check for any extra keys in dict2forkeyinactual_dict:
ifkeynotinexpected_dict:
raiseAssertionError(f"Key mismatch: '{path+key}' was unexpected.")
Have you considered any alternative solutions?
If we don't see a reason to include this in the main library, I can put it in altair ally, although it wouldn't be as visible or easy to access there.
There are already some packages that assert equality of dictionaries and json specs (e.g. deepdiff), but they don't have that easy to understand error messages and seem like unnecessary dependencies to take on.
The text was updated successfully, but these errors were encountered:
This would be very handy! One issue will be the global counter for parameter names, see #3416 where this came up for Streamlit. See here how they solved it on their side.
What is your suggestion?
Would it be useful to have the equivalent of pandas
assert_frame_equal
for Altair charts? I was drafting a function for this to use when grading student submissions and thought maybe it would be beneficial to have more widely available.Example usage:
and
Function draft
This could be extended to e.g. optionally exclude keys from comparisons (such as the data/datasets which should probably be excluded by default).
Have you considered any alternative solutions?
If we don't see a reason to include this in the main library, I can put it in altair ally, although it wouldn't be as visible or easy to access there.
There are already some packages that assert equality of dictionaries and json specs (e.g. deepdiff), but they don't have that easy to understand error messages and seem like unnecessary dependencies to take on.
The text was updated successfully, but these errors were encountered: