QuantEcon / QuantEcon/QuantEcon.py
RFC: Vendor rng_integers instead of importing from SciPy's private _lib._util
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.4k
- Forks
- 2.3k
- Avg merge
- 3d 3h
- Merged PRs (30d)
- 3
Description
Problem
quantecon/util/random.py:9 imports a helper from a private SciPy module:
from scipy._lib._util import rng_integers # noqa: F401
scipy._lib carries no stability guarantee — SciPy may rename, move, or delete rng_integers in any release, including a patch release. Because our requirement is an unbounded scipy>=1.5.0, the day that happens every fresh install of quantecon breaks at import of the affected modules, with no action on our side. The noqa on the import line is the linter having warned us already.
The symbol is re-exported via quantecon/util/__init__.py and used at 13 call sites in 8 modules: markov/core.py:510; game_theory/normal_form_game.py:416; game_theory/logitdyn.py:112,153; game_theory/brd.py:115; game_theory/localint.py:115,180; game_theory/random.py:178; game_theory/game_generators/bimatrix_generators.py:258,262,596,612,614.
Proposed change
Vendor the function instead of importing it — the same pattern this repo already uses for copy_if_needed in quantecon/util/compat.py (copied from SciPy with attribution rather than imported):
- Copy the (small)
rng_integersimplementation intoquantecon/util/random.pywith a provenance comment and SciPy license attribution. - Keep the name and signature identical —
quantecon.util.rng_integers— so zero call sites change. Behavior-preserving by construction. - Add a smoke test pinning the contract (dtype, inclusive/exclusive endpoints,
RandomStatevsGeneratordispatch) so future drift is caught here, not by users.
Acceptance criteria
-
grep -rn "scipy._lib" quantecon/returns nothing - Full suite passes; no public API or seeded-stream change
- New unit test covers both RNG types and endpoint semantics
From the July 2026 technical-debt audit (AI-assisted; claims verified against 28d4b3b on 2026-07-25).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with quantecon/util/random.py and compare its existing import with the vendored copy_if_needed pattern in quantecon/util/compat.py. Inspect the listed rng_integers call sites and run the full suite while adding coverage for both RNG types, endpoint semantics, and dtype behavior. Done means no scipy._lib references remain and the public API and seeded streams are unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100