@@ -136,8 +136,8 @@ def migrate_settings(cls, settings, version):
136136 # type: (Dict, int) -> None
137137 if version < 2 :
138138 if 'auto_apply' in settings :
139- settings ['auto_commit' ] = settings [ 'auto_apply' ]
140- del settings [ 'auto_apply' ]
139+ settings ['auto_commit' ] = settings . get ( 'auto_apply' , True )
140+ settings . pop ( 'auto_apply' , None )
141141
142142 def __init__ (self ):
143143 super ().__init__ ()
@@ -151,11 +151,7 @@ def __init__(self):
151151 layout = QGridLayout ()
152152 bg = gui .radioButtonsInBox (
153153 self .controlArea , self , "optimize_k" , orientation = layout ,
154- box = "Number of Clusters" ,
155- # Because commit is only wrapped when creating the auto_commit
156- # buttons, we can't pass it as the callback here, so we can add
157- # this hacky lambda to call the wrapped commit when necessary
158- callback = lambda : self .commit (),
154+ box = "Number of Clusters" , callback = self .update_method ,
159155 )
160156
161157 layout .addWidget (
@@ -229,18 +225,25 @@ def adjustSize(self):
229225 s = self .sizeHint ()
230226 self .resize (s )
231227
228+ def update_method (self ):
229+ self .table_model .clear_scores ()
230+ self .commit ()
231+
232232 def update_k (self ):
233233 self .optimize_k = False
234+ self .table_model .clear_scores ()
234235 self .commit ()
235236
236237 def update_from (self ):
237238 self .k_to = max (self .k_from + 1 , self .k_to )
238239 self .optimize_k = True
240+ self .table_model .clear_scores ()
239241 self .commit ()
240242
241243 def update_to (self ):
242244 self .k_from = min (self .k_from , self .k_to - 1 )
243245 self .optimize_k = True
246+ self .table_model .clear_scores ()
244247 self .commit ()
245248
246249 def enough_data_instances (self , k ):
@@ -395,17 +398,14 @@ def commit(self):
395398
396399 QTimer .singleShot (100 , self .adjustSize )
397400
398- def invalidate (self , force = False ):
401+ def invalidate (self ):
399402 self .cancel ()
400403 self .Error .clear ()
401404 self .Warning .clear ()
402405 self .clusterings = {}
403406 self .table_model .clear_scores ()
404407
405- if force :
406- self .unconditional_commit ()
407- else :
408- self .commit ()
408+ self .commit ()
409409
410410 def update_results (self ):
411411 scores = [
@@ -437,7 +437,7 @@ def send_data(self):
437437 k = self .k
438438
439439 km = self .clusterings .get (k )
440- if not self .data or km is None or isinstance (km , str ):
440+ if self .data is None or km is None or isinstance (km , str ):
441441 self .Outputs .annotated_data .send (None )
442442 self .Outputs .centroids .send (None )
443443 return
@@ -469,8 +469,14 @@ def send_data(self):
469469 @Inputs .data
470470 @check_sql_input
471471 def set_data (self , data ):
472- self .data = data
473- self .invalidate ()
472+ self .data , old_data = data , self .data
473+
474+ # Do not needlessly recluster the data if X hasn't changed
475+ if old_data and self .data and np .array_equal (self .data .X , old_data .X ):
476+ if self .auto_commit :
477+ self .send_data ()
478+ else :
479+ self .invalidate ()
474480
475481 def send_report (self ):
476482 # False positives (Setting is not recognized as int)
0 commit comments