Fix node ID mapping issues in frc_fgsn and principled_clustering algorithms#255
Merged
GiulioRossetti merged 2 commits intoSep 30, 2025
Merged
Conversation
…rithms Co-authored-by: GiulioRossetti <13123607+GiulioRossetti@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Identify the reasons some tests under cdlib/test/test_community_discovery_models.py fails and proceede to fix the issue patching the implementations
Commit incrementally after testing each fix
Fix node ID mapping issues in frc_fgsn and principled_clustering algorithms
Sep 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two community detection algorithms were failing when used with graphs containing string node IDs:
frc_fgsn()- Failed withIndexError: only integers, slices (...) are valid indicesprincipled_clustering()- Failed withKeyError: '$0$'These failures occurred in the test suite when testing with graphs that have string node labels (e.g.,
'$0$','$1$', etc.) instead of integer IDs.Root Cause
Both functions in
cdlib/algorithms/crisp_partition.pyfollow the same pattern to handle graphs with non-integer node IDs:nx_node_integer_mapping(graph)to convert string node IDs to integers (0, 1, 2, ...)g: A converted graph with integer node IDsmaps: A dictionary to map results back to original node IDsHowever, they were incorrectly passing the original graph (with string nodes) to the internal algorithms instead of the converted graph (with integer nodes). The internal algorithms (
fuzzy_comm()andprincipled()) use numpy arrays indexed by integers, causing failures when string node IDs were used as array indices.Solution
Fixed both functions to pass the converted graph
g(with integer node IDs) to the internal algorithms:Line 1459 in
frc_fgsn():Line 1518 in
principled_clustering():Impact
test_community_discovery_models.pynow passFixes test failures:
test_frc_fgsnandtest_principledOriginal prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.