Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikicc committed Jun 2, 2017
1 parent 0b3e449 commit 8488448
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions Orange/tests/test_discretize.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class TestDiscretizer(TestCase):
def setUp(self):
self.var = Mock(data.ContinuousVariable, number_of_decimals=1)
self.var.name = "x"
self.var.sparse = False

def test_create_discretized_var(self):
dvar = discretize.Discretizer.create_discretized_var(
Expand Down
3 changes: 2 additions & 1 deletion Orange/tests/test_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def test_normalize_transform_by_span_zero_class(self):
self.compare_tables(data_norm, solution)

def test_normalize_sparse(self):
domain = Domain([ContinuousVariable(str(i)) for i in range(3)])
domain = Domain([ContinuousVariable(str(i), sparse=True)
for i in range(3)])
X = sp.csr_matrix(np.array([
[0, 0, 0,],
[0, -1, -2],
Expand Down
21 changes: 18 additions & 3 deletions Orange/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,8 @@ def test_creates_table_with_given_domain_and_row_filter(self):
def test_from_table_sparse_move_some_to_empty_metas(self):
iris = data.Table("iris")
iris.X = sp.csr_matrix(iris.X)
for a in iris.domain.attributes:
a.sparse = True
new_domain = data.domain.Domain(
iris.domain.attributes[:2], iris.domain.class_vars,
iris.domain.attributes[2:], source=iris.domain)
Expand All @@ -1851,19 +1853,24 @@ def test_from_table_sparse_move_some_to_empty_metas(self):
back_iris = data.Table.from_table(iris.domain, new_iris)
self.assertEqual(back_iris.domain, iris.domain)
self.assertTrue(sp.issparse(back_iris.X))
self.assertTrue(sp.issparse(back_iris.metas))
self.assertFalse(sp.issparse(back_iris.metas))
self.assertEqual(back_iris.X.shape, iris.X.shape)
self.assertEqual(back_iris.metas.shape, iris.metas.shape)

for a in iris.domain.attributes:
a.sparse = False

def test_from_table_sparse_move_all_to_empty_metas(self):
iris = data.Table("iris")
iris.X = sp.csr_matrix(iris.X)
for a in iris.domain.attributes:
a.sparse = True
new_domain = data.domain.Domain(
[], iris.domain.class_vars, iris.domain.attributes,
source=iris.domain)
new_iris = data.Table.from_table(new_domain, iris)

self.assertTrue(sp.issparse(new_iris.X))
self.assertFalse(sp.issparse(new_iris.X))
self.assertTrue(sp.issparse(new_iris.metas))
self.assertEqual(new_iris.X.shape, (len(iris), 0))
self.assertEqual(new_iris.metas.shape, (len(iris), 4))
Expand All @@ -1872,13 +1879,18 @@ def test_from_table_sparse_move_all_to_empty_metas(self):
back_iris = data.Table.from_table(iris.domain, new_iris)
self.assertEqual(back_iris.domain, iris.domain)
self.assertTrue(sp.issparse(back_iris.X))
self.assertTrue(sp.issparse(back_iris.metas))
self.assertFalse(sp.issparse(back_iris.metas))
self.assertEqual(back_iris.X.shape, iris.X.shape)
self.assertEqual(back_iris.metas.shape, iris.metas.shape)

for a in iris.domain.attributes:
a.sparse = False

def test_from_table_sparse_move_to_nonempty_metas(self):
brown = data.Table("brown-selected")
brown.X = sp.csr_matrix(brown.X)
for a in brown.domain.attributes:
a.sparse = True
n_attr = len(brown.domain.attributes)
n_metas = len(brown.domain.metas)
new_domain = data.domain.Domain(
Expand All @@ -1901,6 +1913,9 @@ def test_from_table_sparse_move_to_nonempty_metas(self):
self.assertEqual(back_brown.X.shape, brown.X.shape)
self.assertEqual(back_brown.metas.shape, brown.metas.shape)

for a in brown.domain.attributes:
a.sparse = False

def assert_table_with_filter_matches(
self, new_table, old_table,
rows=..., xcols=..., ycols=..., mcols=...):
Expand Down
6 changes: 6 additions & 0 deletions Orange/widgets/data/tests/test_owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def test_check_datetime_disabled(self):
def test_domain_edit_on_sparse_data(self):
iris = Table("iris")
iris.X = sp.csr_matrix(iris.X)
for a in iris.domain.attributes:
a.sparse = True

f = tempfile.NamedTemporaryFile(suffix='.pickle', delete=False)
pickle.dump(iris, f)
Expand All @@ -216,6 +218,10 @@ def test_domain_edit_on_sparse_data(self):
self.assertEqual(iris.X.shape, output.X.shape)
self.assertTrue(sp.issparse(output.X))

for a in iris.domain.attributes:
a.sparse = False


def test_drop_data_when_everything_skipped(self):
"""
No data when everything is skipped. Otherwise Select Rows crashes.
Expand Down
8 changes: 6 additions & 2 deletions Orange/widgets/visualize/tests/test_owscatterplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,20 @@ def test_sparse(self):
"""
table = Table("iris")
table.X = sp.csr_matrix(table.X)
for a in table.domain.attributes:
a.sparse = True

self.assertTrue(sp.issparse(table.X))
table.Y = sp.csr_matrix(table._Y) # pylint: disable=protected-access
self.assertTrue(sp.issparse(table.Y))
self.send_signal(self.widget.Inputs.data, table)
self.widget.set_subset_data(table[:30])
data = self.get_output("Data")

self.assertTrue(data.is_sparse())
self.assertEqual(len(data.domain), 5)

for a in table.domain.attributes:
a.sparse = False


if __name__ == "__main__":
import unittest
Expand Down
5 changes: 5 additions & 0 deletions Orange/widgets/visualize/tests/test_owsieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ def test_sparse_data(self):
self.assertFalse(output.is_sparse())

table.X = sp.csr_matrix(table.X)
for a in table.domain.attributes:
a.sparse = True
self.send_signal(self.widget.Inputs.data, table)
self.assertEqual(len(self.widget.discrete_data.domain), 2)
output = self.get_output("Data")
self.assertTrue(output.is_sparse())

for a in table.domain.attributes:
a.sparse = False

0 comments on commit 8488448

Please sign in to comment.