@@ -165,6 +165,31 @@ def test_continuous_missing(self):
165165 3. , 4. , 2. , 1. , 1. , 1. , 1. ])
166166 self .assertEqual (cont .unknowns , 1 )
167167
168+ def test_continuous_array_with_unknowns (self ):
169+ """
170+ Test array_with_unknowns function
171+ """
172+ d = data .Table ("iris" )
173+ d .Y [:50 ] = np .zeros (50 ) * float ("nan" )
174+ cont = contingency .Continuous (d , "sepal width" )
175+ correct_row_unknowns = [0. , 0. , 1. , 0. , 0. , 0. , 0. , 0. , 1. , 6. , 5. , 5. ,
176+ 2. , 9. , 6. , 2. , 3. , 4. , 2. , 1. , 1. , 1. , 1. ]
177+ correct_row_unknowns_no_zero = [
178+ c for c in correct_row_unknowns if c > 0 ]
179+ correct_values_no_zero = [
180+ v for v , c in zip (cont .values , correct_row_unknowns ) if c > 0 ]
181+
182+ np .testing .assert_almost_equal (cont .row_unknowns , correct_row_unknowns )
183+ arr_unknowns = cont .array_with_unknowns
184+ np .testing .assert_almost_equal (
185+ arr_unknowns [- 1 ][1 ], correct_row_unknowns_no_zero )
186+ np .testing .assert_almost_equal (
187+ arr_unknowns [- 1 ][0 ], correct_values_no_zero )
188+
189+ # check if other match to what we get with __getitem__
190+ for v1 , v2 in zip (arr_unknowns [:- 1 ], cont ):
191+ np .testing .assert_almost_equal (v1 , v2 )
192+
168193 def test_mixedtype_metas (self ):
169194 import Orange
170195 zoo = Orange .data .Table ("zoo" )
@@ -212,7 +237,6 @@ def _construct_sparse():
212237 Y = np .array ([[1 , 2 , 1 , 0 , 0 ]]).T
213238 return data .Table .from_numpy (domain , X , Y )
214239
215-
216240 def test_sparse (self ):
217241 d = self ._construct_sparse ()
218242 cont = contingency .Discrete (d , 5 )
0 commit comments