Skip to content

Exceptions cleanup: narrow catches, remove hidden RNG resets, and make provenance timestamps UTC-aware#1391

Merged
SkBlaz merged 2 commits into
masterfrom
copilot/exceptions-cleanup
Jun 24, 2026
Merged

Exceptions cleanup: narrow catches, remove hidden RNG resets, and make provenance timestamps UTC-aware#1391
SkBlaz merged 2 commits into
masterfrom
copilot/exceptions-cleanup

Conversation

Copilot AI commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

This PR addresses exception hygiene and reproducibility gaps: broad except: blocks were masking failures, two statistics functions were mutating global RNG state via hardcoded np.random.seed(42), and provenance timestamps used deprecated naive UTC creation.

  • Exception handling hardening

    • Replaced bare except: with targeted exception types across affected runtime modules:
      • py3plex/algorithms/robustness_testing.py
      • py3plex/algorithms/statistical_report.py
      • py3plex/uncertainty/community_ensemble.py
      • py3plex/algebra/paths.py
      • py3plex/meta/utils.py
      • py3plex/visualization/multilayer.py
    • This preserves fallback behavior while avoiding swallowing KeyboardInterrupt/SystemExit.
  • RNG behavior in multilayer statistics

    • Removed internal hardcoded seeding from:
      • interdependence(...)
      • resilience(...)
    • Added optional seed parameters and switched to local generators (np.random.default_rng(seed)), so callers control determinism without global RNG side effects.
  • Timezone-aware provenance timestamp

    • Replaced deprecated naive UTC timestamp generation in py3plex/meta/utils.py with timezone-aware UTC output normalized to Z.
  • Focused coverage updates

    • Extended tests/test_multilayer_statistics.py with deterministic seed behavior checks for interdependence and resilience.
    • Added tests/test_meta_utils.py to assert timezone-aware timestamp_utc formatting.
# Before: hidden global RNG mutation
# np.random.seed(42)
# n1, n2 = np.random.choice(all_nodes, size=2, replace=False)

# After: caller-controlled local RNG
rng = np.random.default_rng(seed)
n1, n2 = rng.choice(all_nodes, size=2, replace=False)

Copilot AI changed the title [WIP] Fix bare except clauses and randomness issues Exceptions cleanup: narrow catches, remove hidden RNG resets, and make provenance timestamps UTC-aware Jun 20, 2026
Copilot AI requested a review from SkBlaz June 20, 2026 11:38
@SkBlaz SkBlaz marked this pull request as ready for review June 24, 2026 10:17
@SkBlaz SkBlaz merged commit c82d7b0 into master Jun 24, 2026
37 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.

2 participants