From 848844848703ce83c844d731a82a04bff4cd607f Mon Sep 17 00:00:00 2001 From: nikicc Date: Fri, 2 Jun 2017 23:46:59 +0200 Subject: [PATCH] fixing tests --- Orange/tests/test_discretize.py | 1 + Orange/tests/test_normalize.py | 3 ++- Orange/tests/test_table.py | 21 ++++++++++++++++--- Orange/widgets/data/tests/test_owfile.py | 6 ++++++ .../visualize/tests/test_owscatterplot.py | 8 +++++-- .../widgets/visualize/tests/test_owsieve.py | 5 +++++ 6 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Orange/tests/test_discretize.py b/Orange/tests/test_discretize.py index 373a5d68ff7..16a3f202647 100644 --- a/Orange/tests/test_discretize.py +++ b/Orange/tests/test_discretize.py @@ -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( diff --git a/Orange/tests/test_normalize.py b/Orange/tests/test_normalize.py index c3497aa67d6..85a39b7b85f 100644 --- a/Orange/tests/test_normalize.py +++ b/Orange/tests/test_normalize.py @@ -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], diff --git a/Orange/tests/test_table.py b/Orange/tests/test_table.py index 808a870524b..51c738bec72 100644 --- a/Orange/tests/test_table.py +++ b/Orange/tests/test_table.py @@ -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) @@ -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)) @@ -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( @@ -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=...): diff --git a/Orange/widgets/data/tests/test_owfile.py b/Orange/widgets/data/tests/test_owfile.py index c7430e0f383..469d70f3fa4 100644 --- a/Orange/widgets/data/tests/test_owfile.py +++ b/Orange/widgets/data/tests/test_owfile.py @@ -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) @@ -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. diff --git a/Orange/widgets/visualize/tests/test_owscatterplot.py b/Orange/widgets/visualize/tests/test_owscatterplot.py index 0d2d683cb21..de08412f553 100644 --- a/Orange/widgets/visualize/tests/test_owscatterplot.py +++ b/Orange/widgets/visualize/tests/test_owscatterplot.py @@ -274,9 +274,10 @@ 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") @@ -284,6 +285,9 @@ def test_sparse(self): 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 diff --git a/Orange/widgets/visualize/tests/test_owsieve.py b/Orange/widgets/visualize/tests/test_owsieve.py index 2280ba1ef0d..04fd3639786 100644 --- a/Orange/widgets/visualize/tests/test_owsieve.py +++ b/Orange/widgets/visualize/tests/test_owsieve.py @@ -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