Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] stats: Fix statistics for primitive variables #3722

Merged
merged 1 commit into from
Apr 5, 2019
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: 3 additions & 1 deletion Orange/statistics/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,9 @@ def weighted_mean():
X.shape[0] - non_zero,
non_zero))
else:
nans = (~X.astype(bool)).sum(axis=0) if X.size else np.zeros(X.shape[1])
X_str = X.astype(str)
nans = ((X_str == "nan") | (X_str == "")).sum(axis=0) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have my doubts about a literal 'nan' being treated as missing.

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
9 changes: 5 additions & 4 deletions Orange/tests/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ def test_stats_weights_sparse(self):

def test_stats_non_numeric(self):
X = np.array([
['', 'a', 'b'],
['a', '', 'b'],
['a', 'b', ''],
["", "a", np.nan, 0],
["a", "", np.nan, 1],
["a", "b", 0, 0],
], 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]])
[np.inf, -np.inf, 0, 0, 2, 1],
[np.inf, -np.inf, 0, 0, 0, 3]])

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