Python/Rust Package Methods Check
Review changed Python, Rust, or mixed-language scientific software with emphasis on methodological correctness, numerical robustness, package behavior, tests, and documentation.
Use this for:
- Python packages
- Rust crates
- Python bindings to Rust, C, C++, or Fortran
- scientific CLI tools
- simulation code
- numerical methods
- statistical estimators
- bioinformatics pipelines
- pre-PR review before merging
Do not focus mainly on formatting unless formatting affects correctness, maintainability, or user-facing behavior.
1. Scientific and statistical correctness
Ask:
- What is the target quantity?
- What is observed versus inferred?
- What is an input, hyperparameter, estimator, posterior quantity, diagnostic, or output?
- Are assumptions stated and consistent with the implementation?
- Are transformations, offsets, links, scales, and parameterizations handled correctly?
- Are probability, log-probability, likelihood, loss, and objective functions clearly distinguished?
- Are quantities returned on the intended scale?
- Are uncertainty-related quantities labeled and computed correctly?
- Are defaults scientifically defensible?
- Are preprocessing, filtering, normalization, pseudocounts, or thresholds hiding assumptions?
2. Numerical robustness
Check for:
- unstable subtraction, division, exponentiation, or log operations
- underflow and overflow
- division by zero or near-zero values
- unguarded
log, exp, softmax, logsumexp, sigmoid, or likelihood calculations
- singular, ill-conditioned, or non-positive-definite matrix operations
- incorrect dtype behavior, integer division, precision loss, or silent casting
- incorrect handling of
NaN, Inf, None, missing values, or masked arrays
- poor behavior for small sample sizes, sparse data, rare events, extreme counts, heavy tails, or skewed distributions
- boundary cases such as empty arrays, one-row inputs, one-column inputs, all-zero rows, ties, duplicate IDs, and one-level factors
For Rust specifically, also check:
- panic risk from
unwrap, expect, indexing, slicing, or unchecked assumptions
- misuse of
Result, Option, or error propagation
- unsafe blocks and whether they are justified
- ownership, borrowing, cloning, and allocation patterns that may affect correctness or performance
- numeric conversions using
as that may truncate, overflow, or lose precision
- parallel code for race conditions or nondeterministic outputs
For Python specifically, also check:
- mutable default arguments
- shape/broadcasting bugs
- pandas index alignment bugs
- dtype coercion
- chained assignment
- hidden global state
- random seed behavior
- inconsistent NumPy, pandas, Polars, PyTorch, JAX, or SciPy array semantics
3. API and package behavior
Ask:
- Are public and private APIs separated clearly?
- Are names, arguments, defaults, and return values coherent?
- Are argument checks early and informative?
- Are error messages actionable?
- Is backward compatibility preserved where reasonable?
- Are dependencies necessary and minimal?
- Are examples safe, fast, and reproducible?
- Are CLI arguments documented and stable?
- Are outputs deterministic when they should be?
- Are files written only where the user expects?
For Python packages, check:
pyproject.toml
- package layout
- imports
- optional dependencies
- type hints
- tests
- wheels/build behavior
- CLI entry points
For Rust crates, check:
Cargo.toml
- feature flags
- public API exports
- examples
- docs
- benchmarks
- tests
- error types
4. Tests
Propose the smallest tests that would catch real breakage.
Prefer:
- one minimal regression test over broad rewrites
- edge-case tests for boundary inputs
- deterministic tests for random algorithms
- property-style checks when exact values are hard to specify
- numerical tolerance checks with justified tolerances
- cross-language consistency tests for Python/Rust bindings
Do not suggest large test rewrites unless the current tests cannot detect the risk.
5. Performance
Flag performance only when it affects usability, scalability, or correctness.
Check:
- avoidable quadratic or cubic complexity
- unnecessary copies
- repeated parsing or repeated allocation
- slow loops that should be vectorized or moved to Rust
- memory growth with large matrices, count tables, sparse arrays, or simulation grids
- parallelization that increases memory more than expected
6. Documentation
Flag documentation that no longer matches behavior:
- README
- docstrings
- examples
- vignettes/tutorials
- CLI help
- changelog
- API reference
- mathematical notation
- default values
- output schema
Output format
Return exactly these sections:
Summary
2-4 sentences on what changed and the main risk.
Major issues
For each issue, give:
- Issue
- Why it matters
- Smallest fix
Suggested tests
List minimal tests to add or update.
Documentation updates
List docs, examples, or CLI help that should be updated.
Performance or scalability concerns
Only include concerns that matter for realistic use.
Nice-to-have improvements
Optional cleanup that is not required for correctness.
Behavior:
- Be skeptical about scientific correctness, not just syntax.
- Prefer the smallest correct patch.
- Distinguish correctness issues from maintainability issues.
- If uncertain, say exactly what is uncertain.
- Review first; do not start editing unless explicitly asked.
1---2name: python-rust-package-methods-check3description: Review Python packages, Rust crates, and mixed scientific software for correctness, numerical robustness, APIs, tests, performance, and docs.4---56# Python/Rust Package Methods Check78Review changed Python, Rust, or mixed-language scientific software with emphasis on methodological correctness, numerical robustness, package behavior, tests, and documentation.910Use this for:11- Python packages12- Rust crates13- Python bindings to Rust, C, C++, or Fortran14- scientific CLI tools15- simulation code16- numerical methods17- statistical estimators18- bioinformatics pipelines19- pre-PR review before merging2021Do not focus mainly on formatting unless formatting affects correctness, maintainability, or user-facing behavior.2223## 1. Scientific and statistical correctness2425Ask:2627- What is the target quantity?28- What is observed versus inferred?29- What is an input, hyperparameter, estimator, posterior quantity, diagnostic, or output?30- Are assumptions stated and consistent with the implementation?31- Are transformations, offsets, links, scales, and parameterizations handled correctly?32- Are probability, log-probability, likelihood, loss, and objective functions clearly distinguished?33- Are quantities returned on the intended scale?34- Are uncertainty-related quantities labeled and computed correctly?35- Are defaults scientifically defensible?36- Are preprocessing, filtering, normalization, pseudocounts, or thresholds hiding assumptions?3738## 2. Numerical robustness3940Check for:4142- unstable subtraction, division, exponentiation, or log operations43- underflow and overflow44- division by zero or near-zero values45- unguarded `log`, `exp`, `softmax`, `logsumexp`, sigmoid, or likelihood calculations46- singular, ill-conditioned, or non-positive-definite matrix operations47- incorrect dtype behavior, integer division, precision loss, or silent casting48- incorrect handling of `NaN`, `Inf`, `None`, missing values, or masked arrays49- poor behavior for small sample sizes, sparse data, rare events, extreme counts, heavy tails, or skewed distributions50- boundary cases such as empty arrays, one-row inputs, one-column inputs, all-zero rows, ties, duplicate IDs, and one-level factors5152For Rust specifically, also check:5354- panic risk from `unwrap`, `expect`, indexing, slicing, or unchecked assumptions55- misuse of `Result`, `Option`, or error propagation56- unsafe blocks and whether they are justified57- ownership, borrowing, cloning, and allocation patterns that may affect correctness or performance58- numeric conversions using `as` that may truncate, overflow, or lose precision59- parallel code for race conditions or nondeterministic outputs6061For Python specifically, also check:6263- mutable default arguments64- shape/broadcasting bugs65- pandas index alignment bugs66- dtype coercion67- chained assignment68- hidden global state69- random seed behavior70- inconsistent NumPy, pandas, Polars, PyTorch, JAX, or SciPy array semantics7172## 3. API and package behavior7374Ask:7576- Are public and private APIs separated clearly?77- Are names, arguments, defaults, and return values coherent?78- Are argument checks early and informative?79- Are error messages actionable?80- Is backward compatibility preserved where reasonable?81- Are dependencies necessary and minimal?82- Are examples safe, fast, and reproducible?83- Are CLI arguments documented and stable?84- Are outputs deterministic when they should be?85- Are files written only where the user expects?8687For Python packages, check:8889- `pyproject.toml`90- package layout91- imports92- optional dependencies93- type hints94- tests95- wheels/build behavior96- CLI entry points9798For Rust crates, check:99100- `Cargo.toml`101- feature flags102- public API exports103- examples104- docs105- benchmarks106- tests107- error types108109## 4. Tests110111Propose the smallest tests that would catch real breakage.112113Prefer:114115- one minimal regression test over broad rewrites116- edge-case tests for boundary inputs117- deterministic tests for random algorithms118- property-style checks when exact values are hard to specify119- numerical tolerance checks with justified tolerances120- cross-language consistency tests for Python/Rust bindings121122Do not suggest large test rewrites unless the current tests cannot detect the risk.123124## 5. Performance125126Flag performance only when it affects usability, scalability, or correctness.127128Check:129130- avoidable quadratic or cubic complexity131- unnecessary copies132- repeated parsing or repeated allocation133- slow loops that should be vectorized or moved to Rust134- memory growth with large matrices, count tables, sparse arrays, or simulation grids135- parallelization that increases memory more than expected136137## 6. Documentation138139Flag documentation that no longer matches behavior:140141- README142- docstrings143- examples144- vignettes/tutorials145- CLI help146- changelog147- API reference148- mathematical notation149- default values150- output schema151152## Output format153154Return exactly these sections:155156## Summary1572-4 sentences on what changed and the main risk.158159## Major issues160For each issue, give:161- Issue162- Why it matters163- Smallest fix164165## Suggested tests166List minimal tests to add or update.167168## Documentation updates169List docs, examples, or CLI help that should be updated.170171## Performance or scalability concerns172Only include concerns that matter for realistic use.173174## Nice-to-have improvements175Optional cleanup that is not required for correctness.176177Behavior:178- Be skeptical about scientific correctness, not just syntax.179- Prefer the smallest correct patch.180- Distinguish correctness issues from maintainability issues.181- If uncertain, say exactly what is uncertain.182- Review first; do not start editing unless explicitly asked.