@@ -54,19 +54,22 @@ def test_kmeans_basic():
5454 clusters = cluster .kmeans (phate_op , n_clusters = 3 )
5555
5656 # Should return integer array
57- assert np .issubdtype (clusters .dtype , np .signedinteger ), \
58- f"Expected integer dtype, got { clusters .dtype } "
57+ assert np .issubdtype (
58+ clusters .dtype , np .signedinteger
59+ ), f"Expected integer dtype, got { clusters .dtype } "
5960 print (f"✓ Returns integer dtype: { clusters .dtype } " )
6061
6162 # Should have correct shape
6263 assert len (clusters .shape ) == 1 , f"Expected 1D array, got shape { clusters .shape } "
63- assert len (clusters ) == tree_data .shape [0 ], \
64- f"Expected { tree_data .shape [0 ]} labels, got { len (clusters )} "
64+ assert (
65+ len (clusters ) == tree_data .shape [0 ]
66+ ), f"Expected { tree_data .shape [0 ]} labels, got { len (clusters )} "
6567 print (f"✓ Correct shape: { clusters .shape } " )
6668
6769 # Should have exactly 3 clusters
68- assert len (np .unique (clusters )) == 3 , \
69- f"Expected 3 clusters, got { len (np .unique (clusters ))} "
70+ assert (
71+ len (np .unique (clusters )) == 3
72+ ), f"Expected 3 clusters, got { len (np .unique (clusters ))} "
7073 print (f"✓ Correct number of clusters: { len (np .unique (clusters ))} " )
7174
7275 # Cluster labels should start from 0
@@ -136,8 +139,9 @@ def test_kmeans_max_clusters():
136139 n_clusters = len (np .unique (clusters ))
137140
138141 # Should respect max_clusters (search from 2 to max_k)
139- assert 2 <= n_clusters < max_k , \
140- f"Expected clusters in [2, { max_k } ), got { n_clusters } "
142+ assert (
143+ 2 <= n_clusters < max_k
144+ ), f"Expected clusters in [2, { max_k } ), got { n_clusters } "
141145 print (f"✓ max_clusters={ max_k } : selected { n_clusters } clusters" )
142146
143147 print ("✓ Test 4 PASSED\n " )
@@ -156,8 +160,9 @@ def test_kmeans_random_state():
156160 clusters2 = cluster .kmeans (phate_op , n_clusters = 4 , random_state = 42 )
157161
158162 # Should be identical
159- assert np .array_equal (clusters1 , clusters2 ), \
160- "Same random_state should give identical results"
163+ assert np .array_equal (
164+ clusters1 , clusters2
165+ ), "Same random_state should give identical results"
161166 print ("✓ Same random_state gives identical results" )
162167
163168 # Run with different random_state
@@ -187,10 +192,12 @@ def test_kmeans_deprecated_k_parameter():
187192
188193 # Check warning was raised
189194 assert len (w ) == 1 , f"Expected 1 warning, got { len (w )} "
190- assert issubclass (w [0 ].category , FutureWarning ), \
191- f"Expected FutureWarning, got { w [0 ].category } "
192- assert "k is deprecated" in str (w [0 ].message ).lower (), \
193- f"Unexpected warning message: { w [0 ].message } "
195+ assert issubclass (
196+ w [0 ].category , FutureWarning
197+ ), f"Expected FutureWarning, got { w [0 ].category } "
198+ assert (
199+ "k is deprecated" in str (w [0 ].message ).lower ()
200+ ), f"Unexpected warning message: { w [0 ].message } "
194201 print (f"✓ FutureWarning raised: { w [0 ].message } " )
195202
196203 # Should still work correctly
@@ -217,8 +224,9 @@ def test_silhouette_score_basic():
217224 score = cluster .silhouette_score (phate_op , n_clusters = 3 )
218225
219226 # Should return a float
220- assert isinstance (score , (float , np .floating )), \
221- f"Expected float score, got { type (score )} "
227+ assert isinstance (
228+ score , (float , np .floating )
229+ ), f"Expected float score, got { type (score )} "
222230 print (f"✓ Returns float: { score } " )
223231
224232 # Silhouette score should be in [-1, 1]
@@ -262,8 +270,9 @@ def test_silhouette_score_random_state():
262270 score1 = cluster .silhouette_score (phate_op , n_clusters = 3 , random_state = 42 )
263271 score2 = cluster .silhouette_score (phate_op , n_clusters = 3 , random_state = 42 )
264272
265- assert np .isclose (score1 , score2 ), \
266- f"Expected same scores, got { score1 } and { score2 } "
273+ assert np .isclose (
274+ score1 , score2
275+ ), f"Expected same scores, got { score1 } and { score2 } "
267276 print (f"✓ Reproducible with random_state: { score1 :.4f} " )
268277
269278 print ("✓ Test 9 PASSED\n " )
@@ -305,8 +314,9 @@ def test_kmeans_unfitted_phate():
305314 phate_op = create_unfitted_phate_op ()
306315
307316 # Should raise NotFittedError
308- with pytest .raises (exceptions .NotFittedError ,
309- match = "This PHATE instance is not fitted yet" ):
317+ with pytest .raises (
318+ exceptions .NotFittedError , match = "This PHATE instance is not fitted yet"
319+ ):
310320 cluster .kmeans (phate_op , n_clusters = 3 )
311321 print ("✓ Correctly raises NotFittedError for unfitted operator" )
312322
@@ -343,8 +353,9 @@ def test_kmeans_auto_uses_silhouette():
343353 phate_op , _ , _ = create_simple_phate_op ()
344354
345355 # Get auto-selected clustering
346- clusters_auto = cluster .kmeans (phate_op , n_clusters = "auto" ,
347- max_clusters = 8 , random_state = 42 )
356+ clusters_auto = cluster .kmeans (
357+ phate_op , n_clusters = "auto" , max_clusters = 8 , random_state = 42
358+ )
348359 n_auto = len (np .unique (clusters_auto ))
349360
350361 print (f"Auto-selected: { n_auto } clusters" )
@@ -359,8 +370,7 @@ def test_kmeans_auto_uses_silhouette():
359370 # The auto-selected k should correspond to max silhouette
360371 best_k = np .argmax (silhouette_scores ) + 2 # +2 because range starts at 2
361372
362- assert n_auto == best_k , \
363- f"Auto-selected { n_auto } but best silhouette at k={ best_k } "
373+ assert n_auto == best_k , f"Auto-selected { n_auto } but best silhouette at k={ best_k } "
364374 print (f"✓ Auto mode correctly selected k={ best_k } (max silhouette)" )
365375
366376 print ("✓ Test 13 PASSED\n " )
@@ -388,8 +398,9 @@ def test_clustering_stability():
388398 clusters2 = cluster .kmeans (phate_op2 , n_clusters = 3 , random_state = 42 )
389399
390400 # Should get identical results
391- assert np .array_equal (clusters1 , clusters2 ), \
392- "Same data and parameters should give identical clustering"
401+ assert np .array_equal (
402+ clusters1 , clusters2
403+ ), "Same data and parameters should give identical clustering"
393404 print ("✓ Clustering is reproducible with same data and parameters" )
394405
395406 print ("✓ Test 14 PASSED\n " )
0 commit comments