Skip to content

Commit

Permalink
Gui: Fixups according to improved sparsity
Browse files Browse the repository at this point in the history
  • Loading branch information
nikicc committed Nov 17, 2017
1 parent a0935fa commit 8ed204d
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 29 deletions.
3 changes: 1 addition & 2 deletions Orange/widgets/data/tests/test_owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,7 @@ def test_no_specified_reader(self):
self.assertTrue(self.widget.Error.missing_reader.is_shown())

def test_domain_edit_on_sparse_data(self):
iris = Table("iris")
iris.X = sp.csr_matrix(iris.X)
iris = Table("iris").to_sparse()

f = tempfile.NamedTemporaryFile(suffix='.pickle', delete=False)
pickle.dump(iris, f)
Expand Down
3 changes: 1 addition & 2 deletions Orange/widgets/data/tests/test_owmergedata.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,7 @@ def test_sparse(self):
"""
data = Table("iris")[::25]
data_ed_dense = Table("titanic")[::300]
data_ed_sparse = Table("titanic")[::300]
data_ed_sparse.X = sp.csr_matrix(data_ed_sparse.X)
data_ed_sparse = Table("titanic")[::300].to_sparse()
self.send_signal("Data", data)

self.send_signal("Extra Data", data_ed_dense)
Expand Down
7 changes: 2 additions & 5 deletions Orange/widgets/model/tests/test_tree.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# pylint: disable=protected-access
import numpy as np
import scipy.sparse as sp

from Orange.base import Model
from Orange.data import Table
Expand Down Expand Up @@ -49,8 +48,7 @@ def test_sparse_data_classification(self):
table1 = Table("iris")
self.send_signal("Data", table1)
model_dense = self.get_output("Model")
table2 = Table("iris")
table2.X = sp.csr_matrix(table2.X)
table2 = Table("iris").to_sparse()
self.send_signal("Data", table2)
model_sparse = self.get_output("Model")
self.assertTrue(np.array_equal(model_dense._code, model_sparse._code))
Expand All @@ -64,8 +62,7 @@ def test_sparse_data_regression(self):
table1 = Table("housing")
self.send_signal("Data", table1)
model_dense = self.get_output("Model")
table2 = Table("housing")
table2.X = sp.csr_matrix(table2.X)
table2 = Table("housing").to_sparse()
self.send_signal("Data", table2)
model_sparse = self.get_output("Model")
self.assertTrue(np.array_equal(model_dense._code, model_sparse._code))
Expand Down
3 changes: 1 addition & 2 deletions Orange/widgets/unsupervised/tests/test_owmanifoldlearning.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def _compare_tables(self, _output, n_components):
np.testing.assert_array_equal(self.iris.metas, _output.metas)

def test_sparse_data(self):
data = Table("iris")
data.X = sparse.csr_matrix(data.X)
data = Table("iris").to_sparse()
self.assertTrue(sparse.issparse(data.X))
self.widget.manifold_method_index = 2
self.send_signal(self.widget.Inputs.data, data)
Expand Down
3 changes: 1 addition & 2 deletions Orange/widgets/visualize/owheatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,7 @@ def set_dataset(self, data=None):

if data is not None and sp.issparse(data.X):
try:
data = data.copy()
data.X = data.X.toarray()
data = data.to_dense()
except MemoryError:
data = None
self.Error.not_enough_memory()
Expand Down
8 changes: 1 addition & 7 deletions Orange/widgets/visualize/owscatterplotgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,13 +623,7 @@ def sparse_to_dense(self):
domain = data.domain
all_attrs = domain.variables + domain.metas
attrs = list(set(all_attrs) & attrs)
selected_data = data[:, attrs]
if sp.issparse(selected_data.X):
selected_data.X = selected_data.X.toarray()
if sp.issparse(selected_data.Y):
selected_data.Y = selected_data.Y.toarray()
if sp.issparse(selected_data.metas):
selected_data.metas = selected_data.metas.toarray()
selected_data = data[:, attrs].to_dense()
return selected_data

def _clear_plot_widget(self):
Expand Down
3 changes: 1 addition & 2 deletions Orange/widgets/visualize/owsieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def discretizer(data):
discretize = Discretize(
method=EqualFreq(n=4), remove_const=False,
discretize_classes=True, discretize_metas=True)
return discretize(data)
return discretize(data).to_dense()
return data

if not data.is_sparse() and not init:
Expand All @@ -219,7 +219,6 @@ def discretizer(data):
self.attr_y}
new_domain = data.domain.select_columns(attrs)
data = Table.from_table(new_domain, data)
data.X = data.X.toarray()
return discretizer(data)

@Inputs.features
Expand Down
7 changes: 2 additions & 5 deletions Orange/widgets/visualize/tests/test_owscatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,8 @@ def test_sparse(self):
GH-2152
GH-2157
"""
table = Table("iris")
table.X = sp.csr_matrix(table.X)
self.assertTrue(sp.issparse(table.X))
table.Y = sp.csr_matrix(table._Y) # pylint: disable=protected-access
self.assertTrue(sp.issparse(table.Y))
table = Table("iris").to_sparse(sparse_attributes=True,
sparse_class=True)
self.send_signal(self.widget.Inputs.data, table)
self.widget.set_subset_data(table[:30])
data = self.get_output("Data")
Expand Down
3 changes: 1 addition & 2 deletions Orange/widgets/visualize/tests/test_owsieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from math import isnan
from unittest.mock import patch
import numpy as np
import scipy.sparse as sp

from AnyQt.QtCore import QEvent, QPoint, Qt
from AnyQt.QtGui import QMouseEvent
Expand Down Expand Up @@ -100,7 +99,7 @@ def test_sparse_data(self):
output = self.get_output("Data")
self.assertFalse(output.is_sparse())

table.X = sp.csr_matrix(table.X)
table = table.to_sparse()
self.send_signal(self.widget.Inputs.data, table)
self.assertEqual(len(self.widget.discrete_data.domain), 2)
output = self.get_output("Data")
Expand Down

0 comments on commit 8ed204d

Please sign in to comment.