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 errors in categorical selection #1069

Merged
merged 4 commits into from
Aug 8, 2016
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 @@ -18,6 +18,9 @@ v0.9.0 (unreleased)
``glue.external.qt`` package is now deprecated. The ``get_qapp`` and
``load_ui`` functions are now available in ``glue.utils.qt``.

* Avoid raising a (harmless) error when selecting a region in between two
categorical components.

v0.8.3 (unreleased)
-------------------

Expand Down
6 changes: 3 additions & 3 deletions glue/core/qt/roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from qtpy.QtCore import Qt
from qtpy import QtCore, QtWidgets
from qtpy import QtCore, QtGui, QtWidgets
from glue.core import roi
from glue.utils.qt import mpl_to_qt4_color

Expand Down Expand Up @@ -46,7 +46,7 @@ def paint(self, canvas):

def draw_polygon(self, canvas, x, y):
x, y = self._transform(x, y)
poly = QtWidgets.QPolygon()
poly = QtGui.QPolygon()
points = [QtCore.QPoint(xx, yy) for xx, yy in zip(x, y)]
for p in points:
poly.append(p)
Expand All @@ -70,7 +70,7 @@ def get_painter(self, canvas):
edgecolor = mpl_to_qt4_color(self.plot_opts['edgecolor'],
self.plot_opts['alpha'])

pen = QtWidgets.QPen(edgecolor)
pen = QtGui.QPen(edgecolor)
pen.setWidth(self.plot_opts.get('edgewidth', 0))
p.setPen(pen)

Expand Down
13 changes: 7 additions & 6 deletions glue/core/roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,14 +1219,15 @@ def contains(self, x, y):
within the ROI

"""

check = self._categorical_helper(x)
index = np.minimum(np.searchsorted(self.categories, check),
len(self.categories) - 1)
return self.categories[index] == check
if self.categories is None or len(self.categories) == 0:
return np.zeros(x.shape, dtype=bool)
else:
check = self._categorical_helper(x)
index = np.minimum(np.searchsorted(self.categories, check),
len(self.categories) - 1)
return self.categories[index] == check

def update_categories(self, categories):

self.categories = np.unique(self._categorical_helper(categories))

def defined(self):
Expand Down
5 changes: 5 additions & 0 deletions glue/core/tests/test_roi.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ def test_from_range(self):
np.testing.assert_array_equal(roi.categories,
np.array(list('ghij')))

def test_empty_categories(self):
roi = CategoricalROI()
contains = roi.contains(np.array(['a','b','c']), None)
np.testing.assert_array_equal(contains, [0, 0, 0])


class DummyEvent(object):
def __init__(self, x, y, inaxes=True, key=None):
Expand Down