|
11 | 11 | from Orange.data.util import assure_array_dense |
12 | 12 | from Orange.statistics.util import bincount, countnans, contingency, digitize, \ |
13 | 13 | mean, nanmax, nanmean, nanmedian, nanmin, nansum, nanunique, stats, std, \ |
14 | | - unique, var, nanstd, nanvar, nanmode, nan_to_num, FDR, isnan, any_nan |
| 14 | + unique, var, nanstd, nanvar, nanmode, nan_to_num, FDR, isnan, any_nan, \ |
| 15 | + all_nan |
15 | 16 | from sklearn.utils import check_random_state |
16 | 17 |
|
17 | 18 |
|
@@ -730,6 +731,51 @@ def test_axis_1_with_nans(self, array): |
730 | 731 | np.testing.assert_equal(result, expected) |
731 | 732 |
|
732 | 733 |
|
| 734 | +class TestAllNans(unittest.TestCase): |
| 735 | + def setUp(self) -> None: |
| 736 | + # pylint: disable=bad-whitespace |
| 737 | + self.x_with_nans = np.array([ |
| 738 | + [0., 1., 0., np.nan, 3., 5.], |
| 739 | + [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan], |
| 740 | + [0., 0., 0., np.nan, 7., 6.], |
| 741 | + [0., 0., 0., np.nan, 7., np.nan], |
| 742 | + ]) |
| 743 | + self.x_no_nans = np.arange(12).reshape((3, 4)) |
| 744 | + self.x_only_nans = (np.ones(12) * np.nan).reshape((3, 4)) |
| 745 | + |
| 746 | + @dense_sparse |
| 747 | + def test_axis_none_without_nans(self, array): |
| 748 | + self.assertFalse(all_nan(array(self.x_no_nans))) |
| 749 | + |
| 750 | + @dense_sparse |
| 751 | + def test_axis_none_with_nans(self, array): |
| 752 | + self.assertTrue(all_nan(array(self.x_only_nans))) |
| 753 | + |
| 754 | + @dense_sparse |
| 755 | + def test_axis_0_without_nans(self, array): |
| 756 | + expected = np.array([0, 0, 0, 0], dtype=bool) |
| 757 | + result = all_nan(array(self.x_no_nans), axis=0) |
| 758 | + np.testing.assert_equal(result, expected) |
| 759 | + |
| 760 | + @dense_sparse |
| 761 | + def test_axis_0_with_nans(self, array): |
| 762 | + expected = np.array([0, 0, 0, 1, 0, 0], dtype=bool) |
| 763 | + result = all_nan(array(self.x_with_nans), axis=0) |
| 764 | + np.testing.assert_equal(result, expected) |
| 765 | + |
| 766 | + @dense_sparse |
| 767 | + def test_axis_1_without_nans(self, array): |
| 768 | + expected = np.array([0, 0, 0], dtype=bool) |
| 769 | + result = all_nan(array(self.x_no_nans), axis=1) |
| 770 | + np.testing.assert_equal(result, expected) |
| 771 | + |
| 772 | + @dense_sparse |
| 773 | + def test_axis_1_with_nans(self, array): |
| 774 | + expected = np.array([0, 1, 0, 0], dtype=bool) |
| 775 | + result = all_nan(array(self.x_with_nans), axis=1) |
| 776 | + np.testing.assert_equal(result, expected) |
| 777 | + |
| 778 | + |
733 | 779 | class TestNanModeFixedInScipy(unittest.TestCase): |
734 | 780 |
|
735 | 781 | @unittest.expectedFailure |
|
0 commit comments