Skip to content

Commit

Permalink
Fix serialization of binary component link
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Feb 23, 2018
1 parent 5111a2f commit d335ac0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
23 changes: 18 additions & 5 deletions glue/core/component_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,26 @@ def replace_ids(self, old, new):
self._right.replace_ids(old, new)

def compute(self, data, view=None):
l = self._left
r = self._right
left = self._left
right = self._right
if not isinstance(self._left, numbers.Number):
l = data[self._left, view]
left = data[self._left, view]
if not isinstance(self._right, numbers.Number):
r = data[self._right, view]
return self._op(l, r)
right = data[self._right, view]
return self._op(left, right)

def __gluestate__(self, context):
left = context.id(self._left)
right = context.id(self._right)
operator = context.do(self._op)
return dict(left=left, right=right, operator=operator)

@classmethod
def __setgluestate__(cls, rec, context):
left = context.object(rec['left'])
right = context.object(rec['right'])
operator = context.object(rec['operator'])
return cls(left, right, operator)

def __str__(self):
sym = OPSYM.get(self._op, self._op.__name__)
Expand Down
11 changes: 11 additions & 0 deletions glue/core/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,17 @@ def _load_coordinate_component_link(rec, context):
return CoordinateComponentLink(frm, to, coords, index, pix2world)


@saver(types.BuiltinFunctionType)
def _save_builtin_function(function, context):
ref = "%s.%s" % (function.__module__, function.__name__)
return {'function': ref}


@loader(types.BuiltinFunctionType)
def _load_builtin_function(rec, context):
return lookup_class_with_patches(rec['function'])


@saver(types.FunctionType)
def _save_function(function, context):
ref = "%s.%s" % (function.__module__, function.__name__)
Expand Down
1 change: 1 addition & 0 deletions glue/core/state_path_patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ glue.viewers.table.qt.viewer_widget.TableWidget -> glue.viewers.table.qt.TableVi
glue_vispy_viewers.common.toolbar.PatchedElementSubsetState -> glue.core.subset.ElementSubsetState
glue.plugins.dendro_viewer.qt.viewer_widget.DendroWidget -> glue.plugins.dendro_viewer.qt.DendrogramViewer
glue.plugins.dendro_viewer.layer_artist.DendroLayerArtist -> glue.plugins.dendro_viewer.layer_artist.DendrogramLayerArtist
builtins.builtin_function_or_method -> types.BuiltinFunctionType
2 changes: 1 addition & 1 deletion glue/core/tests/test_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ def test_matplotlib_cmap():
def test_binary_component_link():
d1 = core.Data(x=[1, 2, 3])
d1['y'] = d1.id['x'] + 1
assert_equal(d1['y'], [2, 3, 4])
d2 = clone(d1)
assert_equal(d1['x'], [1, 2, 3])
assert_equal(d2['y'], [2, 3, 4])


Expand Down

0 comments on commit d335ac0

Please sign in to comment.