Add comprehensive precomputed input pytest coverage#176
Open
MattScicluna wants to merge 1 commit intomainfrom
Open
Add comprehensive precomputed input pytest coverage#176MattScicluna wants to merge 1 commit intomainfrom
MattScicluna wants to merge 1 commit intomainfrom
Conversation
Pull Request Test Coverage Report for Build 22677665907Details
💛 - Coveralls |
There was a problem hiding this comment.
Pull request overview
Adds a new pytest module to validate PHATE’s handling of precomputed distance/affinity inputs, including alias behavior, sparse inputs, and expected error cases.
Changes:
- Introduces regression tests for
knn_dist="precomputed"vs explicitprecomputed_distance/precomputed_affinity. - Adds coverage for sparse COO precomputed inputs.
- Adds error-path tests for invalid matrices and unsupported out-of-sample transforms.
Comments suppressed due to low confidence (7)
Python/test/test_precomputed.py:11
- Directly mutating
sys.pathinside tests is brittle and can mask packaging/import issues (e.g., importing the repo checkout instead of the installed distribution). Prefer configuring the test environment via proper packaging (editable install in CI),PYTHONPATH, orconftest.py/pytest configuration so imports resolve naturally.
import sys
import os
# Add parent directory to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
Python/test/test_precomputed.py:46
- These tests emit a lot of
print()output. In pytest suites this adds noise and makes failures harder to scan in CI logs. Prefer relying on assertions alone, or use pytest’s reporting mechanisms (e.g.,-vvtest names) and only print diagnostic context when asserting/raising (or usecaplog/logging if needed).
print("\n" + "=" * 70)
print("TEST 1: precomputed alias with random valid distance matrix")
print("=" * 70)
Python/test/test_precomputed.py:34
- Setting
n_jobs=-1in unit tests can unnecessarily saturate CI runners and can introduce nondeterminism depending on internal parallel reductions. Consider usingn_jobs=1(or parametrizing) for test stability and predictable runtime.
return dict(knn=7, t=10, n_jobs=-1, verbose=False, random_state=42)
Python/test/test_precomputed.py:81
- The tolerance
atol=1e-10is extremely strict for algorithms involving graph construction/eigendecompositions and can lead to flaky tests across BLAS/LAPACK implementations, OSes, or minor dependency changes. Use a more realistic tolerance (e.g., 1e-6/1e-7) and/or addrtol, and consider comparing a more stable invariant if exact embedding coordinates can vary.
assert np.allclose(
emb_alias, emb_distance, atol=1e-10
), "Alias and explicit distance mode diverged"
Python/test/test_precomputed.py:150
- The
match=...patterns are tightly coupled to exact error-message wording (and could break on minor copy edits). Consider using a more flexible regex (e.g., matching key terms with case-insensitivity) or validating a more stable property (exception type + minimal distinctive substring) to reduce brittleness.
with pytest.raises(ValueError, match="square matrix"):
phate.PHATE(knn_dist="precomputed", **create_precomputed_kwargs()).fit_transform(
D_non_square
)
Python/test/test_precomputed.py:1
- For pytest test modules, a shebang and
__main__runner are typically unnecessary and can be undesirable in some test discovery/packaging contexts. It’s cleaner to rely onpytestinvocation from the command line/CI and keep test files import-only.
#!/usr/bin/env python
Python/test/test_precomputed.py:198
- For pytest test modules, a shebang and
__main__runner are typically unnecessary and can be undesirable in some test discovery/packaging contexts. It’s cleaner to rely onpytestinvocation from the command line/CI and keep test files import-only.
if __name__ == "__main__":
pytest.main([__file__, "-v"])
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
No description provided.