Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Make the sparse path observable and controllable (.is_sparse, densify warning, per-call sparse=)

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

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python

Research direction

Start by reading the sparse paths at linopy/expressions.py:2570, 3291, 3319, 2606-2609 and linopy/constraints.py:1427, then inspect Grid and the existing sparse_groupby option. Define how repr(), shape, sizes, coords, dims and isnull avoid densifying before implementing the public state, warnings and per-call controls. Done means sparse fallbacks are observable and controllable without changing default behavior.

Written by the indexing model from the issue text.

Description

enhancement sparse

[!NOTE]
The following content was generated by AI.

Describe the feature you'd like to see

Make the sparse path observable and controllable. Child of #756.

Right now a user cannot tell whether their build stayed sparse. There is no .is_sparse property, no marker in the repr, and no warning when the backing is dropped. Four separate code paths fall back to dense by returning None, all silently: _sparse_matmul (linopy/expressions.py:2570), _try_csr_merge (3319), _aligned (3291) and csr_rhs (linopy/constraints.py:1427).

Combined with the fact that reading repr() or .sizes destroys the backing in place (filed separately as a bug), this makes the feature very hard to use deliberately on anything larger than a toy model.

Three parts:

  1. Expose the state. A public .is_sparse on LinearExpression, and a marker in __repr__ — provided the repr itself stops densifying.
  2. Explain the fallbacks. An opt-in warning, for example options["warn_on_densify"], naming the operation that dropped the backing. Off by default, so nothing changes for existing users.
  3. Per-call control. A sparse= flag on @/dot and merge, mirroring groupby(...).sum(sparse=True). Today @ contracts sparsely but returns a dense object unless the input was already CSR-backed or the global options["sparse_groupby"] is set (expressions.py:2606-2609), which is a surprising coupling between an unrelated option and the result's representation. #961 explicitly deferred this flag.

Implementation ideas

Serving shape, sizes, coords, dims and isnull from the existing Grid is a prerequisite for a non-densifying repr, and is worth doing on its own: Grid already holds all of it.

Dominant language
Python
Stars
257
Forks
87
Avg merge
1d 15h
Merged PRs (30d)
32

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.

More from PyPSA/linopy

All issues in PyPSA/linopy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.