From cd31ed53916101c8f3e9bae6571614bfbe3dd1dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavlin=20Poli=C4=8Dar?= Date: Sun, 10 Feb 2019 14:24:36 +0100 Subject: [PATCH] OwLouvain: Move data preprocessing to separate function --- .../unsupervised/owlouvainclustering.py | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Orange/widgets/unsupervised/owlouvainclustering.py b/Orange/widgets/unsupervised/owlouvainclustering.py index 18ae49bf08a..3e6f1cecf9c 100644 --- a/Orange/widgets/unsupervised/owlouvainclustering.py +++ b/Orange/widgets/unsupervised/owlouvainclustering.py @@ -145,6 +145,14 @@ def __init__(self): callback=lambda: self._on_auto_commit_changed(), ) # type: QWidget + def _preprocess_data(self): + if self.preprocessed_data is None: + if self.normalize: + normalizer = preprocess.Normalize(center=False) + self.preprocessed_data = normalizer(self.data) + else: + self.preprocessed_data = self.data + def _apply_pca_changed(self): self.controls.pca_components.setEnabled(self.apply_pca) self._invalidate_graph() @@ -208,11 +216,9 @@ def cancel(self): self.__set_state_ready() def commit(self): - # pylint: disable=too-many-branches self.__commit_timer.stop() self.__invalidated = False self._set_modified(False) - self.Error.clear() # Cancel current running task self.__cancel_task(wait=False) @@ -221,24 +227,14 @@ def commit(self): self.__set_state_ready() return - # Make sure the dataset is ok - if len(self.data.domain.attributes) < 1: - self.Error.empty_dataset() - self.__set_state_ready() - return + self.Error.clear() if self.partition is not None: self.__set_state_ready() self._send_data() return - # Preprocess the dataset - if self.preprocessed_data is None: - if self.normalize: - normalizer = preprocess.Normalize(center=False) - self.preprocessed_data = normalizer(self.data) - else: - self.preprocessed_data = self.data + self._preprocess_data() state = TaskState(self) @@ -425,6 +421,12 @@ def set_data(self, data): # Clear internal state self.clear() self._invalidate_pca_projection() + + # Make sure the dataset is ok + if self.data is not None and len(self.data.domain.attributes) < 1: + self.Error.empty_dataset() + self.data = None + if self.data is None: return