Add transition table feature to changelog - #48
Conversation
Use key=str to satisfy type checker when sorting sets of int | str keys.
key=str would sort integers lexicographically (1, 10, 2). Since keys are homogeneous at runtime, sorted() works correctly; the type checker just cannot prove it from the union type.
- TransitionTable is now Generic[TableKey] where TableKey is constrained to int or str, eliminating union types and type: ignore comments throughout the class. - Add @overload signatures to transition_counts() and transition_probabilities() so callers get precise return types. - Extract _normalise_counts() and _validate_destination() helpers to reduce duplication in trajectory.py.
Replace transition_counts(by=...) and transition_probabilities(by=...) with four explicit methods: - transition_counts_by_site() - transition_counts_by_label() - transition_probabilities_by_site() - transition_probabilities_by_label() Each method has a precise return type (TransitionTable[int] or TransitionTable[str]) with no overloads, casts, or unions needed. Remove the now-unnecessary TransitionValidationTestCase (no by parameter to validate).
- Update changelog to reference the actual method names (transition_counts_by_site, transition_counts_by_label, etc.) - Add test for unlabelled site transitioning to an invalid index, covering the _validate_destination call at trajectory.py:254-255
There was a problem hiding this comment.
Pull request overview
Updates the transition table functionality across the codebase, including API changes in Trajectory, improved typing for TransitionTable, test updates, and a changelog entry documenting the feature.
Changes:
- Refactors
Trajectorytransition aggregation into explicit*_by_site()/*_by_label()methods and adds shared helpers for validation + normalisation. - Makes
TransitionTablegeneric over key type (int/str) and updates associated type annotations. - Updates unit tests and the changelog to reflect the new transition table APIs.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_trajectory.py | Updates tests to call the new transition_*_by_site/_by_label APIs; adds a new invalid-destination test. |
| site_analysis/transition_table.py | Introduces TransitionTable[TableKey] generics and updates method type hints accordingly. |
| site_analysis/trajectory.py | Replaces by=... parameter APIs with explicit per-site/per-label methods; adds helper methods for validation and normalisation. |
| site_analysis/site_collection.py | Adds a -> None return annotation to __init__. |
| CHANGELOG.md | Adds entries describing the transition table APIs and exports. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
This PR updates the project to reflect and test the finalized “transition table” API introduced in v1.7.0, including new Trajectory transition aggregation methods and the TransitionTable data structure.
Changes:
- Updates trajectory transition tests to use
transition_counts_by_site/_by_labelandtransition_probabilities_by_site/_by_label, and adds a new regression test for invalid destination indices from an unlabelled source site. - Improves typing of
TransitionTableby making it generic over its key type (intorstr). - Adds v1.7.0 changelog entries documenting the new APIs and
TransitionTableexport.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_trajectory.py | Renames test call sites to the new *_by_site/_by_label APIs; adds coverage for invalid destination handling in label aggregation. |
| site_analysis/transition_table.py | Makes TransitionTable generic over key type and simplifies get() typing. |
| site_analysis/trajectory.py | Replaces the prior by=-parameter API with explicit per-site/per-label methods and shared validation/normalisation helpers. |
| site_analysis/site_collection.py | Adds an explicit -> None return annotation to __init__. |
| CHANGELOG.md | Documents the new transition-table-related APIs under v1.7.0. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
transition_counts_by_site(),transition_counts_by_label(),transition_probabilities_by_site(),transition_probabilities_by_label(), andTransitionTableunder v1.7.0