Skip to content

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

Description

@mmcky

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions