Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Orange/statistics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def stats(X, weights=None, compute_variance=False):
is_numeric = np.issubdtype(X.dtype, np.number)
is_sparse = issparse(X)

if is_numeric and not is_sparse:
if X.size and is_numeric and not is_sparse:
nans = np.isnan(X).sum(axis=0)
return np.column_stack((
np.nanmin(X, axis=0),
Expand All @@ -188,7 +188,7 @@ def stats(X, weights=None, compute_variance=False):
X.shape[1] - non_zero,
non_zero))
else:
nans = ~X.astype(bool).sum(axis=0)
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]),
Expand Down
4 changes: 4 additions & 0 deletions Orange/tests/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def test_stats(self):
X[1, 1] = np.nan
np.testing.assert_equal(stats(X), [[0, 2, 1, 0, 0, 2],
[1, 1, 1, 0, 1, 1]])
# empty table should return ~like metas
X = X[:0]
np.testing.assert_equal(stats(X), [[np.inf, -np.inf, 0, 0, 0, 0],
[np.inf, -np.inf, 0, 0, 0, 0]])

def test_stats_sparse(self):
X = csr_matrix(np.identity(5))
Expand Down