Skip to content
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

Fix how we deal with component IDs for linked components #1270

Merged
merged 1 commit into from
Mar 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ v0.11.0 (unreleased)
v0.10.2 (unreleased)
--------------------

* Fixed a bug that caused components that were linked to then disappear from
drop-down lists of available components in new viewers. [#1270]

* Fixed a bug that caused Data.find_component_id to return incorrect results
when string components were present in the data. [#1269]

Expand Down
7 changes: 4 additions & 3 deletions glue/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ def add_component(self, component, label, hidden=False):

if isinstance(label, ComponentID):
component_id = label
component_id.parent = self
if component_id.parent is None:
component_id.parent = self
else:
component_id = ComponentID(label, hidden=hidden, parent=self)

Expand Down Expand Up @@ -471,7 +472,7 @@ def visible_components(self):
:rtype: list
"""
return [cid for cid, comp in self._components.items()
if not cid.hidden and not comp.hidden]
if not cid.hidden and not comp.hidden and cid.parent is self]

@property
def coordinate_components(self):
Expand Down Expand Up @@ -931,7 +932,7 @@ def update_values_from_data(self, data):
if cname in new_labels - old_labels:
cid = data.find_component_id(cname)
comp_new = data.get_component(cname)
self.add_component(comp_new, cid)
self.add_component(comp_new, cid.label)

# Update data label
self.label = data.label
Expand Down
3 changes: 0 additions & 3 deletions glue/core/link_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ def _add_deriveable_components(self, data):
for cid, link in six.iteritems(links):
d = DerivedComponent(data, link)
if cid not in data.components:
# Need to hide component since we don't want to show components
# that are auto-generated in datasets by default.
cid.hidden = True
data.add_component(d, cid)

@property
Expand Down
42 changes: 39 additions & 3 deletions glue/core/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,8 @@ def test_update_values_from_data():
assert d1a not in d1.components
assert d1b in d1.components
assert d2b not in d1.components
assert d2c in d1.components
assert d2c not in d1.components
assert [cid.label for cid in d1.visible_components] == ['b', 'c']
assert d1.shape == (4,)


Expand Down Expand Up @@ -624,8 +625,7 @@ def test_update_values_from_data_order():

d2.update_values_from_data(d1)

assert d2.visible_components == [d2.id['j'], d2.id['a'], d1.id['c'],
d1.id['b'], d1.id['f']]
assert [cid.label for cid in d2.visible_components] == ['j', 'a', 'c', 'b', 'f']


def test_find_component_id_with_cid():
Expand All @@ -639,3 +639,39 @@ def test_find_component_id_with_cid():

assert d1.find_component_id(d1.id['a']) is d1.id['a']
assert d1.find_component_id(d1.id['b']) is d1.id['b']


def test_linked_component_visible():

# Regression test for a bug that caused components to become hidden once
# they were linked with another component.

from ..link_helpers import LinkSame
from ..data_collection import DataCollection

d1 = Data(x=[1], y=[2])
d2 = Data(w=[3], v=[4])

assert not d1.id['x'].hidden
assert not d2.id['w'].hidden

dc = DataCollection([d1, d2])
dc.add_link(LinkSame(d1.id['x'], d2.id['w']))

assert d1.id['x'] is d2.id['x']
assert d1.id['w'] is d2.id['w']

assert not d1.id['x'].hidden
assert not d2.id['w'].hidden

assert not d1.id['w'].hidden
assert not d2.id['x'].hidden

assert d1.id['x'].parent is d1
assert d1.id['y'].parent is d1

assert d2.id['w'].parent is d2
assert d2.id['v'].parent is d2

assert d1.visible_components == [d1.id['x'], d1.id['y']]
assert d2.visible_components == [d2.id['v'], d2.id['w']]