QuantEcon / QuantEcon/QuantEcon.py

ENH: Plan the scipy.sparse matrix-to-array migration

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

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
2.4k
Forks
2.3k
Avg merge
3d 3h
Merged PRs (30d)
3

Description

Problem

markov/core.py, markov/ddp.py, markov/random.py, _graph_tools.py, and game_theory/localint.py are written against scipy.sparse matrix classes (csr_matrix, coo_matrix). SciPy's announced direction is sparse arrays; the matrix classes — whose semantics rest on np.matrix, itself slated for removal — are on the way out. Our dependence is behavioral, not just nominal: markov/core.py:201 comments that row_sums is np.matrix (ndim=2) and the surrounding reduction code relies on that quirk. And it is user-visible: public APIs accept and return these types (MarkovChain docstrings advertise scipy.sparse.csr_matrix).

Proposed change (staged)
  1. Now: accept both matrix and array inputs everywhere (sp.issparse already covers both); add a test leg that feeds csr_array inputs through MarkovChain / DiscreteDP.
  2. Next minor: convert internals to array semantics (explicit-axis reductions replacing np.matrix-shaped sums — removes the core.py:201 reliance).
  3. Announced release: switch sparse return types to arrays with a changelog notice and, if warranted, a one-release FutureWarning on the affected attributes.
Acceptance criteria
  • Suite green under sparse-array inputs end-to-end
  • No internal reliance on np.matrix semantics
  • Return-type change announced before it ships

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 by reading markov/core.py, especially line 201, then review markov/ddp.py, markov/random.py, _graph_tools.py, and game_theory/localint.py for sparse matrix assumptions. Exercise MarkovChain and DiscreteDP with csr_array inputs, then use the acceptance criteria to assess array compatibility, removal of np.matrix reliance, and release-notice requirements.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.