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
9 changes: 9 additions & 0 deletions Orange/widgets/unsupervised/owdistances.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Error(OWWidget.Error):
no_continuous_features = Msg("No continuous features")
dense_metric_sparse_data = Msg("Selected metric does not support sparse data")
empty_data = Msg("Empty data (shape = {})")
too_few_observations = Msg("Too few observations for the number of dimensions")

class Warning(OWWidget.Warning):
ignoring_discrete = Msg("Ignoring discrete features")
Expand Down Expand Up @@ -129,6 +130,14 @@ def compute_distances(self, metric, data):
self.Error.empty_data(data.X.shape)
return

if isinstance(metric, distance.MahalanobisDistance):
n, m = data.X.shape
if self.axis == 1:
n, m = m, n
if n <= m:
self.Error.too_few_observations()
return

if isinstance(metric, distance.MahalanobisDistance):
# Mahalanobis distance has to be trained before it can be used
# to compute distances
Expand Down
8 changes: 7 additions & 1 deletion Orange/widgets/unsupervised/tests/test_owdistances.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from Orange.data import Table
from Orange.distance import MahalanobisDistance
from Orange.distance import MahalanobisDistance, Mahalanobis
from Orange.widgets.unsupervised.owdistances import OWDistances, METRICS
from Orange.widgets.tests.base import WidgetTest

Expand Down Expand Up @@ -40,3 +40,9 @@ def test_error_message(self):
self.assertTrue(self.widget.Error.no_continuous_features.is_shown())
self.send_signal("Data", None)
self.assertFalse(self.widget.Error.no_continuous_features.is_shown())

def test_mahalanobis_error(self):
self.widget.axis = 1
self.send_signal("Data", self.iris)
self.widget.compute_distances(Mahalanobis, self.iris)
self.assertTrue(self.widget.Error.too_few_observations.is_shown())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please configure PyCharm to always include new line on the last line of file?

http://stackoverflow.com/questions/36043061/automatically-add-newline-on-save-in-pycharm