QuantEcon / QuantEcon/QuantEcon.py

RFC: Vendor rng_integers instead of importing from SciPy's private _lib._util

Open
#868 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

high-priority refactor
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):

  1. Copy the (small) rng_integers implementation into quantecon/util/random.py with a provenance comment and SciPy license attribution.
  2. Keep the name and signature identical — quantecon.util.rng_integers — so zero call sites change. Behavior-preserving by construction.
  3. Add a smoke test pinning the contract (dtype, inclusive/exclusive endpoints, RandomState vs Generator dispatch) 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.