Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix binary synchronization and make Image use binary values #1643
Fixes #1642 by working around an underscore bug.
This also makes the image use a binary value so that we have at least one core widget using the binary values and messages.
This means that custom deserializers must not return a DataView or ArrayBuffer (other typed arrays like Uint8Array are fine, though).
from ipywidgets import Image from io import BytesIO import numpy as np from scipy.misc import imsave x = np.zeros((255, 255), dtype=np.uint8) x[:] = np.arange(255) b = BytesIO() imsave(b, x, format='png') im = Image(layout=dict(width='100px', height='100px', border='1px solid red')) im
and also make sure the image is displayed when the page is refreshed.
@maartenbreddels - our problem is more serious than my simple workaround. Since underscore is doing the deep compare, any arraybuffer or dataview object anywhere nested in the JSON of a deserialized trait is going to have this issue.
I'm tempted to just override the backbone function and insert a special-case call to our own isequal.
Note that lodash has specific references to typed arrays, indicating they handle that case: https://github.com/lodash/lodash/blob/8e631dfcd496bc355ee7ceeb959421b0788b9bbc/.internal/baseIsEqualDeep.js#L56