Skip to content

Commit 08da18a

Browse files
authored
Merge pull request #3722 from VesnaT/stats_fix
[FIX] stats: Fix statistics for primitive variables
2 parents 399c4ef + 44af12f commit 08da18a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Orange/statistics/util.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ def weighted_mean():
361361
X.shape[0] - non_zero,
362362
non_zero))
363363
else:
364-
nans = (~X.astype(bool)).sum(axis=0) if X.size else np.zeros(X.shape[1])
364+
X_str = X.astype(str)
365+
nans = ((X_str == "nan") | (X_str == "")).sum(axis=0) \
366+
if X.size else np.zeros(X.shape[1])
365367
return np.column_stack((
366368
np.tile(np.inf, X.shape[1]),
367369
np.tile(-np.inf, X.shape[1]),

Orange/tests/test_statistics.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,14 @@ def test_stats_weights_sparse(self):
118118

119119
def test_stats_non_numeric(self):
120120
X = np.array([
121-
['', 'a', 'b'],
122-
['a', '', 'b'],
123-
['a', 'b', ''],
121+
["", "a", np.nan, 0],
122+
["a", "", np.nan, 1],
123+
["a", "b", 0, 0],
124124
], dtype=object)
125125
np.testing.assert_equal(stats(X), [[np.inf, -np.inf, 0, 0, 1, 2],
126126
[np.inf, -np.inf, 0, 0, 1, 2],
127-
[np.inf, -np.inf, 0, 0, 1, 2]])
127+
[np.inf, -np.inf, 0, 0, 2, 1],
128+
[np.inf, -np.inf, 0, 0, 0, 3]])
128129

129130
def test_nanmin_nanmax(self):
130131
warnings.filterwarnings("ignore", r".*All-NaN slice encountered.*")

0 commit comments

Comments
 (0)