From 58ca34de2251adcffdf92b4cdba03e718afe9df6 Mon Sep 17 00:00:00 2001 From: "Brett M. Morris" Date: Wed, 20 Mar 2024 12:13:36 -0400 Subject: [PATCH] prevent children of children in data associations --- jdaviz/app.py | 11 ++++++++++- jdaviz/configs/imviz/plugins/parsers.py | 1 - jdaviz/tests/test_app.py | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/jdaviz/app.py b/jdaviz/app.py index 295c329c79..68a308c949 100644 --- a/jdaviz/app.py +++ b/jdaviz/app.py @@ -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"): @@ -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 diff --git a/jdaviz/configs/imviz/plugins/parsers.py b/jdaviz/configs/imviz/plugins/parsers.py index 06cbb44263..b6ea47938d 100644 --- a/jdaviz/configs/imviz/plugins/parsers.py +++ b/jdaviz/configs/imviz/plugins/parsers.py @@ -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") diff --git a/jdaviz/tests/test_app.py b/jdaviz/tests/test_app.py index 9179af4350..454f8f3770 100644 --- a/jdaviz/tests/test_app.py +++ b/jdaviz/tests/test_app.py @@ -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') \ No newline at end of file