Skip to content

Commit e7308c8

Browse files
committed
bottlechest.stats: return zeros for empty tables
1 parent 7f464a6 commit e7308c8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Orange/statistics/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def stats(X, weights=None, compute_variance=False):
165165
is_numeric = np.issubdtype(X.dtype, np.number)
166166
is_sparse = issparse(X)
167167

168-
if is_numeric and not is_sparse:
168+
if X.size and is_numeric and not is_sparse:
169169
nans = np.isnan(X).sum(axis=0)
170170
return np.column_stack((
171171
np.nanmin(X, axis=0),
@@ -188,7 +188,7 @@ def stats(X, weights=None, compute_variance=False):
188188
X.shape[1] - non_zero,
189189
non_zero))
190190
else:
191-
nans = ~X.astype(bool).sum(axis=0)
191+
nans = ~X.astype(bool).sum(axis=0) if X.size else np.zeros(X.shape[1])
192192
return np.column_stack((
193193
np.tile(np.inf, X.shape[1]),
194194
np.tile(-np.inf, X.shape[1]),

Orange/tests/test_statistics.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ def test_stats(self):
3333
X[1, 1] = np.nan
3434
np.testing.assert_equal(stats(X), [[0, 2, 1, 0, 0, 2],
3535
[1, 1, 1, 0, 1, 1]])
36+
# empty table should return ~like metas
37+
X = X[:0]
38+
np.testing.assert_equal(stats(X), [[np.inf, -np.inf, 0, 0, 0, 0],
39+
[np.inf, -np.inf, 0, 0, 0, 0]])
3640

3741
def test_stats_sparse(self):
3842
X = csr_matrix(np.identity(5))

0 commit comments

Comments
 (0)