44import os
55import pickle
66import unittest
7- from unittest .mock import Mock , MagicMock , patch
7+ from unittest .mock import Mock
88import numpy as np
99
10- import Orange
11- from Orange .data import Domain , Table , DiscreteVariable
12- from Orange . preprocess import *
13- from Orange .preprocess . discretize import *
14- from Orange .preprocess .fss import *
15- from Orange . preprocess . impute import *
10+ from Orange . data import Table
11+ from Orange .preprocess import EntropyMDL , DoNotImpute , Default , Average , SelectRandomFeatures , EqualFreq , \
12+ RemoveNaNColumns , DropInstances
13+ from Orange .preprocess import EqualWidth , SelectBestFeatures
14+ from Orange .preprocess .preprocess import Preprocess , Scale , Randomize , Continuize , Discretize , Impute , SklImpute , \
15+ Normalize , ProjectCUR , ProjectPCA , RemoveConstant
1616from Orange .util import OrangeDeprecationWarning
1717
1818
1919class TestPreprocess (unittest .TestCase ):
2020 def test_read_data_calls_reader (self ):
21- class MockPreprocessor (Orange . preprocess . preprocess . Preprocess ):
21+ class MockPreprocessor (Preprocess ):
2222 __init__ = Mock (return_value = None )
2323 __call__ = Mock ()
2424 @classmethod
2525 def reset (cls ):
2626 cls .__init__ .reset_mock ()
2727 cls .__call__ .reset_mock ()
2828
29- table = Mock (Orange . data . Table )
29+ table = Mock (Table )
3030 MockPreprocessor (1 , 2 , a = 3 )(table )
3131 MockPreprocessor .__init__ .assert_called_with (1 , 2 , a = 3 )
3232 MockPreprocessor .__call__ .assert_called_with (table )
@@ -52,53 +52,32 @@ def test_refuse_data_in_constructor(self):
5252 expected = self .assertRaises if is_CI else self .assertWarns
5353 with expected (OrangeDeprecationWarning ):
5454 try :
55- Orange . preprocess . preprocess . Preprocess (Table ('iris' ))
55+ Preprocess (Table ('iris' ))
5656 except NotImplementedError :
5757 # Expected from default Preprocess.__call__
5858 pass
5959
6060
61- class RemoveConstant (unittest .TestCase ):
61+ class TestRemoveConstant (unittest .TestCase ):
6262 def test_remove_columns (self ):
6363 X = np .random .rand (6 , 4 )
6464 X [:, (1 ,3 )] = 5
6565 X [3 , 1 ] = np .nan
6666 X [1 , 1 ] = np .nan
67- data = Orange . data . Table (X )
68- d = Orange . preprocess . preprocess . RemoveConstant ()(data )
67+ data = Table (X )
68+ d = RemoveConstant ()(data )
6969 self .assertEqual (len (d .domain .attributes ), 2 )
7070
71- pp_rc = Orange . preprocess . preprocess . RemoveConstant ()
71+ pp_rc = RemoveConstant ()
7272 d = pp_rc (data )
7373 self .assertEqual (len (d .domain .attributes ), 2 )
7474
7575 def test_nothing_to_remove (self ):
76- data = Orange . data . Table ("iris" )
77- d = Orange . preprocess . preprocess . RemoveConstant ()(data )
76+ data = Table ("iris" )
77+ d = RemoveConstant ()(data )
7878 self .assertEqual (len (d .domain .attributes ), 4 )
7979
8080
81- class TestRemoveNanClass (unittest .TestCase ):
82- def test_remove_nan_classes (self ):
83- table = Table ("imports-85" )
84- self .assertTrue (np .isnan (table .Y ).any ())
85- table = RemoveNaNClasses ()(table )
86- self .assertTrue (not np .isnan (table .Y ).any ())
87-
88- def test_remove_nan_classes_multiclass (self ):
89- domain = Domain ([DiscreteVariable ("a" , values = "01" )],
90- [DiscreteVariable ("b" , values = "01" ),
91- DiscreteVariable ("c" , values = "01" )])
92- table = Table (domain , [[0 , 1 , np .nan ],
93- [1 , np .nan , 0 ],
94- [1 , 0 , 1 ],
95- [1 , np .nan , np .nan ]])
96- table = RemoveNaNClasses ()(table )
97- self .assertTrue (not np .isnan (table ).any ())
98- self .assertEqual (table .domain , domain )
99- self .assertEqual (len (table ), 1 )
100-
101-
10281class TestScaling (unittest .TestCase ):
10382 @classmethod
10483 def setUpClass (cls ):
@@ -122,7 +101,7 @@ def test_scaling_median_stddev(self):
122101class TestReprs (unittest .TestCase ):
123102 def test_reprs (self ):
124103 preprocs = [Continuize , Discretize , Impute , SklImpute , Normalize ,
125- Randomize , RemoveNaNClasses , ProjectPCA , ProjectCUR , Scale ,
104+ Randomize , ProjectPCA , ProjectCUR , Scale ,
126105 EqualFreq , EqualWidth , EntropyMDL , SelectBestFeatures ,
127106 SelectRandomFeatures , RemoveNaNColumns , DoNotImpute , DropInstances ,
128107 Average , Default ]
@@ -132,6 +111,7 @@ def test_reprs(self):
132111 new_preproc = eval (repr_str )
133112 self .assertEqual (repr (new_preproc ), repr_str )
134113
114+
135115class TestEnumPickling (unittest .TestCase ):
136116 def test_continuize_pickling (self ):
137117 c = Continuize (multinomial_treatment = Continuize .FirstAsBase )
0 commit comments