Skip to content

Commit f35ef56

Browse files
Add tests, pylint fixes
1 parent 5c1ee54 commit f35ef56

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

Orange/preprocess/preprocess.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,11 @@ def __init__(self,
606606
normalize_datetime=False,
607607
center=Scale.Mean,
608608
scale=Scale.Std):
609-
self.normalize_pps = Normalize(zero_based, norm_type, transform_class, ~(center is not False), normalize_datetime)
609+
self.normalize_pps = Normalize(zero_based,
610+
norm_type,
611+
transform_class,
612+
~(center is not False),
613+
normalize_datetime)
610614
self.scale_pps = Scale(center=Scale.NoCentering, scale=scale)
611615

612616
def __call__(self, data):

Orange/tests/test_preprocess.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
SelectRandomFeatures, EqualFreq, RemoveNaNColumns, DropInstances, \
1515
EqualWidth, SelectBestFeatures, RemoveNaNRows, Preprocess, Scale, \
1616
Randomize, Continuize, Discretize, Impute, SklImpute, Normalize, \
17-
ProjectCUR, ProjectPCA, RemoveConstant
17+
ProjectCUR, ProjectPCA, RemoveConstant, SmartNormalize
1818
from Orange.util import OrangeDeprecationWarning
1919

2020

@@ -166,3 +166,25 @@ def test_scaling_pickling(self):
166166
c1 = pickle.loads(s)
167167
self.assertIs(c1.center, c.center)
168168
self.assertIs(c1.scale, c.scale)
169+
170+
171+
class TestSmartNormalize(unittest.TestCase):
172+
"""
173+
Checks if output for sparse data is the same as for Scale
174+
preprocessor. For dense data the output should match that
175+
of Normalize preprocessor.
176+
"""
177+
178+
def test_dense_pps(self):
179+
data = Table("iris")
180+
true_out = Normalize()(data)
181+
out = SmartNormalize()(data)
182+
np.testing.assert_array_equal(out, true_out)
183+
184+
def test_sparse_pps(self):
185+
data = Table("iris")
186+
data.X = csr_matrix(data.X)
187+
out = SmartNormalize()(data)
188+
true_out = Scale(center=Scale.NoCentering)(data)
189+
np.testing.assert_array_equal(out, true_out)
190+

Orange/widgets/model/owsvm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Outputs(OWBaseLearner.Outputs):
3232
support_vectors = Output("Support vectors", Table, explicit=True)
3333

3434
class Warning(OWWidget.Warning):
35-
sparse_data = Msg('Input data is sparse, default preprocessing is to scale it. If you want mean centering, use preprocessing widget.')
35+
sparse_data = Msg('Input data is sparse, default preprocessing is to scale it.')
3636
outdated_learner = Msg("Press Apply to submit changes.")
3737

3838
#: Different types of SVMs

Orange/widgets/model/tests/test_owsvm.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Test methods with long descriptive names can omit docstrings
22
# pylint: disable=missing-docstring
3+
from scipy.sparse import csr_matrix
4+
35
from Orange.widgets.model.owsvm import OWSVM
46
from Orange.widgets.tests.base import (
57
WidgetTest,
68
DefaultParameterMapping,
79
ParameterMapping,
810
WidgetLearnerTestMixin
911
)
12+
from Orange.data import Table
1013

1114

1215
class TestOWSVMClassification(WidgetTest, WidgetLearnerTestMixin):
@@ -87,3 +90,16 @@ def test_kernel_spins(self):
8790
self.widget.kernel_box.buttons[i].click()
8891
self.assertEqual([self.widget._kernel_params[j].box.isHidden()
8992
for j in range(3)], hidden)
93+
94+
def test_sparse_warning(self):
95+
"""Check if the user is warned about sparse input"""
96+
data = Table("iris")
97+
data.X = csr_matrix(data.X)
98+
self.send_signal("Data", data)
99+
self.assertTrue(self.widget.Warning.sparse_data.is_shown())
100+
101+
def test_dense_input(self):
102+
data = Table("iris")
103+
self.send_signal("Data", data)
104+
self.assertFalse(self.widget.Warning.sparse_data.is_shown())
105+

0 commit comments

Comments
 (0)