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] ScatterPlot: Fix crash when coloring by column of unknowns #2061

Merged
merged 1 commit into from
Mar 3, 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
6 changes: 3 additions & 3 deletions Orange/widgets/visualize/owscatterplot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from AnyQt.QtCore import QSize, Qt, QTimer
from AnyQt.QtCore import Qt, QTimer
from AnyQt.QtGui import (
QPen, QFont, QFontInfo, QPalette, QKeySequence,
)
Expand Down Expand Up @@ -162,7 +162,7 @@ def __init__(self):
box = gui.vBox(self.controlArea, "Axis Data")
dmod = DomainModel
self.xy_model = DomainModel(dmod.MIXED, valid_types=dmod.PRIMITIVE)
gui.comboBox(
self.cb_attr_x = gui.comboBox(
box, self, "attr_x", label="Axis x:", callback=self.update_attr,
model=self.xy_model, **common_options)
self.cb_attr_y = gui.comboBox(
Expand Down Expand Up @@ -409,7 +409,7 @@ def handleNewSignals(self):
self.graph.new_data(self.data_metas_X, self.subset_data)
if self.attribute_selection_list and \
all(attr in self.graph.domain
for attr in self.attribute_selection_list):
for attr in self.attribute_selection_list):
Copy link
Contributor

@kernc kernc Mar 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was indented OK before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pylint complained and that is why I added 4 spaces.

self.attr_x = self.attribute_selection_list[0]
self.attr_y = self.attribute_selection_list[1]
self.attribute_selection_list = None
Expand Down
7 changes: 5 additions & 2 deletions Orange/widgets/visualize/owscatterplotgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import pyqtgraph as pg
from pyqtgraph.graphicsItems.ViewBox import ViewBox
import pyqtgraph.graphicsItems.ScatterPlotItem
from pyqtgraph.graphicsItems.ImageItem import ImageItem
from pyqtgraph.graphicsItems.LegendItem import LegendItem, ItemSample
from pyqtgraph.graphicsItems.ScatterPlotItem import ScatterPlotItem
from pyqtgraph.graphicsItems.TextItem import TextItem
Expand Down Expand Up @@ -298,7 +297,11 @@ def __init__(self, min_v, max_v):
"""
super().__init__()
dif = max_v - min_v if max_v != min_v else 1
decimals = -floor(log10(dif))
if np.isnan(dif):
min_v = 0
dif = decimals = 1
else:
decimals = -floor(log10(dif))
resolution = 10 ** -decimals
bins = ceil(dif / resolution)
if bins < 6:
Expand Down
21 changes: 18 additions & 3 deletions Orange/widgets/visualize/tests/test_owscatterplot.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring
from unittest.mock import MagicMock

import numpy as np

from AnyQt.QtCore import QRectF

from Orange.data import Table, Domain, ContinuousVariable, DiscreteVariable
from Orange.widgets.tests.base import WidgetTest, WidgetOutputsTestMixin
from Orange.widgets.tests.base import WidgetTest, WidgetOutputsTestMixin, datasets
from Orange.widgets.visualize.owscatterplot import \
OWScatterPlot, ScatterPlotVizRank
from Orange.widgets.tests.utils import simulate


class TestOWScatterPlot(WidgetTest, WidgetOutputsTestMixin):
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_score_heuristics(self):
def test_optional_combos(self):
domain = self.data.domain
d1 = Domain(domain.attributes[:2], domain.class_var,
[domain.attributes[2]])
[domain.attributes[2]])
t1 = Table(d1, self.data)
self.send_signal("Data", t1)
self.widget.graph.attr_size = domain.attributes[2]
Expand Down Expand Up @@ -102,3 +102,18 @@ def test_report_on_empty(self):
self.widget.report_plot.assert_not_called()
self.widget.report_caption.assert_not_called()
self.widget.report_items.assert_not_called()

def test_data_column_nans(self):
"""
ValueError cannot convert float NaN to integer.
In case when all column values are NaN then it throws that error.
GH-2061
"""
table = datasets.data_one_column_nans()
self.send_signal("Data", table)

simulate.combobox_activate_item(self.widget.cb_attr_color, "b")
simulate.combobox_activate_item(self.widget.cb_attr_x, "a")
simulate.combobox_activate_item(self.widget.cb_attr_y, "a")

self.widget.update_graph()