Skip to content

Commit

Permalink
Merge pull request #1269 from astrofrog/fix-find-component-id
Browse files Browse the repository at this point in the history
Fixed a bug that caused Data.find_component_id to return incorrect results
  • Loading branch information
astrofrog committed Mar 22, 2017
1 parent 96f11f2 commit cd9e75d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Full changelog
v0.10.2 (unreleased)
--------------------

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

* Fixed a bug that caused errors to appear in the console log after a
table viewer was closed. [#1267]

Expand Down
13 changes: 11 additions & 2 deletions glue/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,9 +528,18 @@ def find_component_id(self, label):
label in the primary and one in the derived components, the primary
one takes precedence.
"""

for cid_set in (self.primary_components, self.derived_components):
result = [cid for cid in cid_set if
cid.label == label or cid is label]

result = []
for cid in cid_set:
if isinstance(label, ComponentID):
if cid is label:
result.append(cid)
else:
if cid.label == label:
result.append(cid)

if len(result) == 1:
return result[0]
elif len(result) > 1:
Expand Down
13 changes: 13 additions & 0 deletions glue/core/tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,3 +626,16 @@ def test_update_values_from_data_order():

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


def test_find_component_id_with_cid():

# Regression test for a bug that caused Data.find_component_id to return
# True erroneously when passing a component ID.

d1 = Data()
d1['a'] = ['a', 'b', 'c']
d1['b'] = [1, 2, 3]

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

0 comments on commit cd9e75d

Please sign in to comment.