Skip to content

Commit

Permalink
prevent children of children in data associations
Browse files Browse the repository at this point in the history
  • Loading branch information
bmorris3 committed Mar 20, 2024
1 parent fe40115 commit 58ca34d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion jdaviz/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1283,10 +1283,12 @@ def add_data(self, data, data_label=None, notify_done=True, parent=None):
The name associated with this data. If none is given, label is pulled
from the input data (if `~glue.core.data.Data`) or a generic name is
generated.
notify_done: bool
notify_done : bool
Flag controlling whether a snackbar message is set when the data is
added to the app. Set to False to avoid overwhelming the user if
lots of data is getting loaded at once.
parent : str, optional
Associate the added Data entry as the child of layer ``parent``.
"""

if not data_label and hasattr(data, "label"):
Expand All @@ -1300,6 +1302,13 @@ def add_data(self, data, data_label=None, notify_done=True, parent=None):
# manage associated Data entries:
self._add_assoc_data_as_parent(data_label)
if parent is not None:
# Does the parent Data have a parent? If so, raise error:
parent_of_parent = self._get_assoc_data_parent(parent)
if parent_of_parent is not None:
raise NotImplementedError('Data associations are currently supported '
'between root layers (without parents) and their '
f'children, but the proposed parent "{parent}" has '
f'parent "{parent_of_parent}".')
self._set_assoc_data_as_child(data_label, new_parent_label=parent)

# Send out a toast message
Expand Down
1 change: 0 additions & 1 deletion jdaviz/configs/imviz/plugins/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ def _parse_image(app, file_obj, data_label, ext=None, parent=None):

# TODO: generalize/centralize this for use in other configs too
if parent is not None and ext == 'DQ':
print('data', data.main_components)
# nans are used to mark "good" flags in the DQ colormap, so
# convert DQ array to float to support nans:
cid = data.get_component("DQ")
Expand Down
4 changes: 4 additions & 0 deletions jdaviz/tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,7 @@ def test_data_associations(imviz_helper):

assert imviz_helper.app._get_assoc_data_children('parent_data') == ['child_data']
assert imviz_helper.app._get_assoc_data_parent('child_data') == 'parent_data'

with pytest.raises(NotImplementedError):
# we don't (yet) allow children of children:
imviz_helper.load_data(data_child, data_label='grandchild_data', parent='child_data')

0 comments on commit 58ca34d

Please sign in to comment.