Skip to content

Fix node ID mapping issues in frc_fgsn and principled_clustering algorithms#255

Merged
GiulioRossetti merged 2 commits into
masterfrom
copilot/fix-5c2a654a-f40b-4d7d-b0fe-36c2dc1977b1
Sep 30, 2025
Merged

Fix node ID mapping issues in frc_fgsn and principled_clustering algorithms#255
GiulioRossetti merged 2 commits into
masterfrom
copilot/fix-5c2a654a-f40b-4d7d-b0fe-36c2dc1977b1

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 30, 2025

Problem

Two community detection algorithms were failing when used with graphs containing string node IDs:

  • frc_fgsn() - Failed with IndexError: only integers, slices (...) are valid indices
  • principled_clustering() - Failed with KeyError: '$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.py follow the same pattern to handle graphs with non-integer node IDs:

  1. Call nx_node_integer_mapping(graph) to convert string node IDs to integers (0, 1, 2, ...)
  2. Receive back:
    • g: A converted graph with integer node IDs
    • maps: A dictionary to map results back to original node IDs

However, 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() and principled()) 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():

# Before
communities, fuzz_assoc = fuzzy_comm(graph, theta, eps, r)

# After
communities, fuzz_assoc = fuzzy_comm(g, theta, eps, r)

Line 1518 in principled_clustering():

# Before
communities, fuzz_assoc = principled(graph, cluster_count)

# After
communities, fuzz_assoc = principled(g, cluster_count)

Impact

  • ✅ All 74 tests in test_community_discovery_models.py now pass
  • ✅ Both functions correctly handle graphs with string node IDs
  • ✅ Both functions continue to work with integer node IDs
  • ✅ No breaking changes to existing functionality
  • ✅ Minimal surgical changes (only 2 variable references modified)

Fixes test failures: test_frc_fgsn and test_principled

Original prompt

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


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…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
@GiulioRossetti GiulioRossetti marked this pull request as ready for review September 30, 2025 09:30
@GiulioRossetti GiulioRossetti merged commit c0412d6 into master Sep 30, 2025
5 checks passed
@GiulioRossetti GiulioRossetti deleted the copilot/fix-5c2a654a-f40b-4d7d-b0fe-36c2dc1977b1 branch September 30, 2025 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants