Skip to content

Fix flaky local assortativity test#175

Merged
eggpig merged 1 commit into
pybind11from
fix/localassort-flaky-test
Jun 8, 2026
Merged

Fix flaky local assortativity test#175
eggpig merged 1 commit into
pybind11from
fix/localassort-flaky-test

Conversation

@eggpig

@eggpig eggpig commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR removes the random node attributes from TestLocalAssort.test_karateclub and replaces them with deterministic, contiguous labels.

The previous test used:

random.choice([0, 1, 2, 3, 4, 5])

without setting a random seed. This could randomly produce a non-contiguous label set such as [0, 1, 2, 3, 5]. localAssort assumes node attribute indices are contiguous and start from 0, which is also documented in the function docstring. When the generated labels skipped a category but still included label 5, the sparse indicator matrix was created with too few columns and SciPy raised:

ValueError: axis 1 index 5 exceeds matrix dimension 5

Root Cause

The failing GitHub Actions run on Python 3.12 was caused by test randomness, not by the HIF fix and not by a Python 3.12-specific implementation regression. The 3.12 job happened to sample a bad non-contiguous label set; other matrix jobs sampled valid data and passed.

Changes

  • Remove the unused random import.
  • Replace random karateclub labels with deterministic labels:
np.arange(node_num, dtype=np.int32) % 6

This keeps six categories in the test while guaranteeing labels are contiguous from 0 to 5.

Validation

Local pytest was intentionally not run per maintainer request. GitHub Actions will validate the full pytest matrix automatically for this PR and again on merge to pybind11.

Lightweight local check run:

  • git diff --check

@eggpig eggpig marked this pull request as ready for review June 8, 2026 09:01
@eggpig eggpig merged commit 8b14964 into pybind11 Jun 8, 2026
12 checks passed
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.

1 participant