Bug
FINCH() raises UnboundLocalError: cannot access local variable 'requested_c' where it is not associated with a value when req_clust is not None and the requested number of clusters is already exactly present in num_clust.
Root cause
In finch.py (lines 363–373 in v0.2.2), the req_clust not in num_clust branch only handles the mismatch cases (too large, or needs sub-clustering). When req_clust is an exact match, the entire inner block is skipped and requested_c is never assigned before the return statement.
if req_clust is not None:
if req_clust not in num_clust: # False when exact match → block skipped
if req_clust > num_clust[0]:
requested_c = c[:, 0]
else:
requested_c = req_numclust(...)
# no else → requested_c undefined when req_clust in num_clust
else:
requested_c = None
return c, num_clust, requested_c # UnboundLocalError
Fix
Add an else branch to handle the exact-match case:
if req_clust is not None:
if req_clust not in num_clust:
if req_clust > num_clust[0]:
requested_c = c[:, 0]
else:
requested_c = req_numclust(...)
else:
requested_c = c[:, num_clust.index(req_clust)]
else:
requested_c = None
Reproduction
Any dataset where FINCH produces a partition with exactly req_clust clusters will trigger this. Confirmed on v0.2.2 (latest).
Bug
FINCH()raisesUnboundLocalError: cannot access local variable 'requested_c' where it is not associated with a valuewhenreq_clustis notNoneand the requested number of clusters is already exactly present innum_clust.Root cause
In
finch.py(lines 363–373 in v0.2.2), thereq_clust not in num_clustbranch only handles the mismatch cases (too large, or needs sub-clustering). Whenreq_clustis an exact match, the entire inner block is skipped andrequested_cis never assigned before thereturnstatement.Fix
Add an
elsebranch to handle the exact-match case:Reproduction
Any dataset where FINCH produces a partition with exactly
req_clustclusters will trigger this. Confirmed on v0.2.2 (latest).