Skip to content

Commit

Permalink
Merge pull request #12 from jfoster17/fix-incompatible-subsets-in-table
Browse files Browse the repository at this point in the history
Improve tables for incompatible subsets
  • Loading branch information
astrofrog authored Jul 19, 2024
2 parents 22c3e05 + 11eeadd commit 37dd079
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
24 changes: 22 additions & 2 deletions glue_qt/viewers/table/data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,24 @@ def _update_visible(self):
Given which layers are visible or not, convert order to order_visible
after applying the current filter_mask
"""

self.data_by_row_and_column.cache_clear()

# We want to make visible subsets that were previously invisible
# because they were incompatible subsets. This requires some
# extra calls to to_mask() and could probably be optimized.

for layer_artist in self._table_viewer.layers:
if isinstance(layer_artist.layer, BaseData):
continue

if not layer_artist.enabled:
try:
mask = layer_artist.layer.to_mask()
except IncompatibleAttribute:
continue
layer_artist.enabled = True
layer_artist.visible = True

# First, if the data layer is visible, show all rows
for layer_artist in self._table_viewer.layers:
if layer_artist.visible and isinstance(layer_artist.layer, BaseData):
Expand All @@ -192,7 +207,11 @@ def _update_visible(self):
visible = np.zeros(self.order.shape, dtype=bool)
for layer_artist in self._table_viewer.layers:
if layer_artist.visible:
mask = layer_artist.layer.to_mask()[self.order]
try:
mask = layer_artist.layer.to_mask()[self.order]
except IncompatibleAttribute:
layer_artist.disable_incompatible_subset()
continue
if DASK_INSTALLED and isinstance(mask, da.Array):
mask = mask.compute()
visible |= mask
Expand Down Expand Up @@ -221,6 +240,7 @@ def update(self):
self._refresh()

def clear(self):
self.visible = False
self._refresh()


Expand Down
43 changes: 37 additions & 6 deletions glue_qt/viewers/table/tests/test_data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from ..data_viewer import DataTableModel, TableViewer

from glue.core.edit_subset_mode import AndNotMode, OrMode, ReplaceMode
from glue.tests.helpers import requires_pyqt_gt_59_or_pyside2


class TestDataTableModel():
Expand Down Expand Up @@ -461,7 +460,6 @@ def test_incompatible_subset():
assert refresh2.call_count == 0


@requires_pyqt_gt_59_or_pyside2
def test_table_incompatible_attribute():
"""
Regression test for a bug where the table viewer generates an
Expand All @@ -484,27 +482,60 @@ def test_table_incompatible_attribute():
sg1 = dc.new_subset_group('invalid', d1.id['x'] <= 3)

gapp.show()
process_events()
process_events(0.5)

assert len(viewer.layers) == 2
assert not viewer.layers[1].visible
assert viewer.layers[0].visible
assert not viewer.layers[1].visible

# This subset can be shown in the viewer
sg2 = dc.new_subset_group('valid', d2.id['a'] == 'a')

process_events(0.5)

assert len(viewer.layers) == 3
assert viewer.layers[2].visible
assert not viewer.layers[1].visible
assert viewer.layers[0].visible
assert not viewer.layers[1].visible
assert viewer.layers[2].visible

# The original IncompatibleAttribute was thrown
# here as making the data layer invisible made
# DataTableModel._update_visible() try and draw
# the invalid subset
viewer.layers[0].visible = False

process_events(0.5)

assert not viewer.layers[0].visible
assert not viewer.layers[1].visible
assert viewer.layers[2].visible

# Another IncompatibleAttribute was thrown here
# as an invalid subset was attempted to be added
# to a table viewer showing only a subset

sg3 = dc.new_subset_group('invalid', d1.id['y'] > 6)

process_events(0.5)

assert len(viewer.layers) == 4
assert not viewer.layers[0].visible
assert not viewer.layers[1].visible
assert viewer.layers[2].visible
assert not viewer.layers[3].visible

# A previously disabled layer artist should
# be renabled when it can be visualized

sg1.subset_state = d2.id['b'] == 'b'

process_events(0.5)

assert len(viewer.layers) == 4
assert not viewer.layers[0].visible
assert viewer.layers[1].visible
assert viewer.layers[2].visible
assert not viewer.layers[3].visible


def test_table_with_dask_column():
Expand Down

0 comments on commit 37dd079

Please sign in to comment.