diff --git a/Orange/statistics/util.py b/Orange/statistics/util.py index 8b244db7225..f4cd6341cd6 100644 --- a/Orange/statistics/util.py +++ b/Orange/statistics/util.py @@ -195,7 +195,7 @@ def stats(X, weights=None, compute_variance=False): X.shape[1] - non_zero, non_zero)) else: - nans = ~X.astype(bool).sum(axis=0) if X.size else np.zeros(X.shape[1]) + nans = (~X.astype(bool)).sum(axis=0) if X.size else np.zeros(X.shape[1]) return np.column_stack(( np.tile(np.inf, X.shape[1]), np.tile(-np.inf, X.shape[1]), diff --git a/Orange/tests/test_statistics.py b/Orange/tests/test_statistics.py index 65d603a41ea..d2f84414b4d 100644 --- a/Orange/tests/test_statistics.py +++ b/Orange/tests/test_statistics.py @@ -69,3 +69,13 @@ def test_stats_weights_sparse(self): weights = np.array([1, 3]) np.testing.assert_equal(stats(X, weights), [[0, 2, 1.5, 0, 1, 1], [1, 3, 2.5, 0, 0, 2]]) + + def test_stats_non_numeric(self): + X = np.array([ + ['', 'a', 'b'], + ['a', '', 'b'], + ['a', 'b', ''], + ], dtype=object) + np.testing.assert_equal(stats(X), [[np.inf, -np.inf, 0, 0, 1, 2], + [np.inf, -np.inf, 0, 0, 1, 2], + [np.inf, -np.inf, 0, 0, 1, 2]])