Skip to content

refactor(csr): use pandas/xarray-style verbs for CSRLinearExpression and Grid methods #1018

Description

@FabianHofmann

Note

The following content was generated by AI.

Describe the feature you'd like to see

linopy/csr.py names the methods of CSRLinearExpression and Grid as past participles (summed, renamed, reindexed, ...). They return a new frozen object, never mutate. pandas and xarray use plain verbs for the same copy-returning operations (df.rename, da.reindex, fillna, ...), so the CSR layer diverges from the convention of the ecosystem linopy builds on.

Proposal: rename them to pandas/xarray-style verbs. Pure refactor, no behavior change.

current proposed
CSRLinearExpression.summed(dims) sum(dims)
aggregated(grid, rows) aggregate(grid, rows)
renamed(names) rename(names)
reindexed(grid, fill) reindex(grid, fill)
filled(value) fillna(value)
taken(rows, grid) take(rows, grid)
added(other) add(other)
scaled(factor) mul(factor)
contracted(...) dot(...)
pruned() prune()
with_const(const) assign_const(const) (or keep)
Grid.renamed / reordered / conformed / combined rename / transpose / conform / combine
# today
expr._csr.aggregated(grid, rows).filled(0.0)
expr._csr.scaled(-1.0)
# proposed
expr._csr.aggregate(grid, rows).fillna(0.0)
expr._csr.mul(-1.0)

Trade-off to decide: LinearExpression already exposes the xarray verbs publicly. After the rename, expr.sum() and expr._csr.sum() share a name but differ in signature and semantics (e.g. the CSR sum takes a grid-level dim list and keeps explicit zero coefficients). The current participles keep the internal sparse layer visibly separate from the public dense API. The _csr attribute and the CSRLinearExpression type arguably mark that boundary well enough on their own.

Activity

  1. added
    sparseSparse / CSR-backed expressions and constraints
    refactorInternal change with no user-facing behavior change
    on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorInternal change with no user-facing behavior changesparseSparse / CSR-backed expressions and constraints

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions