Skip to content

Ipyplotly test fixes #974

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

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle recursive equality of lists, tuples, and dicts that contain nu…
…mpy arrays
  • Loading branch information
Jon M. Mease committed Feb 21, 2018
commit 27d41776bef33f5be1ab7ebf96a3a8dd583fc894
10 changes: 10 additions & 0 deletions plotly/basedatatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,16 @@ def _in_batch_mode(self):
def _vals_equal(v1, v2):
if isinstance(v1, np.ndarray) or isinstance(v2, np.ndarray):
return np.array_equal(v1, v2)
elif isinstance(v1, (list, tuple)):
# Handle recursive equality on lists and tuples
return (isinstance(v2, (list, tuple)) and
len(v1) == len(v2) and
all(BasePlotlyType._vals_equal(e1, e2) for e1, e2 in zip(v1, v2)))
elif isinstance(v1, dict):
# Handle recursive equality on dicts
return (isinstance(v2, dict) and
set(v1.keys()) == set(v2.keys()) and
all(BasePlotlyType._vals_equal(v1[k], v2[k])) for k in v1)
else:
return v1 == v2

Expand Down