Skip to content

feat: add method wrapper for xr.align#426

Merged
FabianHofmann merged 3 commits intomasterfrom
feat/add-align
Mar 14, 2025
Merged

feat: add method wrapper for xr.align#426
FabianHofmann merged 3 commits intomasterfrom
feat/add-align

Conversation

@coroa
Copy link
Copy Markdown
Member

@coroa coroa commented Mar 12, 2025

Changes proposed in this Pull Request

Adds a wrapper which allows aligning linear expressions and dataarrays and variables.

Usage

>>> import linopy as lp
>>> m = lp.Model()
>>> x = m.add_variables(pd.Series([0, 0]), 1, name="x")
>>> alpha = xr.DataArray([1, 2], [[1, 2]])
>>> x_a, alpha = lp.align(x, alpha)
>>> x_a
Variable (dim_0: 1)
-------------------
[1]: x[1] ∈ [0, 1]

Alternative

Note that there would also be the alternative implementation strategy to implement the Alignable protocol for Variable and LinearExpression.

https://github.com/pydata/xarray/blob/852ad1135b9b8c46d8e301c9badbe898bd6d262d/xarray/core/types.py#L125-L166

but i did not test that, and i am unsure whether we could choose dimension exclusions that way.

Checklist

  • Code changes are sufficiently documented; i.e. new functions contain docstrings and further explanations may be given in doc.
  • Unit tests for new features were added (if applicable).
  • A note for the release notes doc/release_notes.rst of the upcoming release is included.
  • I consent to the release of this PR's code under the MIT license.

@coroa coroa requested a review from FabianHofmann March 12, 2025 11:32
@coroa coroa changed the title Add method wrapper for xr.align feat: add method wrapper for xr.align Mar 12, 2025
@FabianHofmann FabianHofmann merged commit 639f126 into master Mar 14, 2025
3 of 5 checks passed
@FabianHofmann FabianHofmann deleted the feat/add-align branch March 14, 2025 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants