Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Upcoming Version
* Add ``format_labels()`` on ``Constraints``/``Variables`` and ``format_infeasibilities()`` on ``Model`` that return strings instead of printing to stdout, allowing usage with logging, storage, or custom output handling. Deprecate ``print_labels()`` and ``print_infeasibilities()``.
* Add ``fix()``, ``unfix()``, and ``fixed`` to ``Variable`` and ``Variables`` for fixing variables to values via equality constraints. Supports automatic rounding for integer/binary variables.
* Add ``relax()``, ``unrelax()``, and ``relaxed`` to ``Variable`` and ``Variables`` for LP relaxation of integer/binary variables. Supports partial relaxation via filtered views (e.g. ``m.variables.integers.relax()``). Semi-continuous variables raise ``NotImplementedError``.
* Add compatibility to latest xarray version.


Version 0.6.6
Expand Down
7 changes: 3 additions & 4 deletions linopy/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def sum(self, use_fallback: bool = False, **kwargs: Any) -> LinearExpression:
index.names = [str(col) for col in orig_group.columns]
index.name = GROUP_DIM
new_coords = Coordinates.from_pandas_multiindex(index, GROUP_DIM)
ds = xr.Dataset(ds.assign_coords(new_coords))
ds = ds.assign_coords(new_coords)

ds = ds.rename({GROUP_DIM: final_group_name})
return LinearExpression(ds, self.model)
Expand Down Expand Up @@ -391,8 +391,7 @@ def __init__(self, data: Dataset | Any | None, model: Model) -> None:
coeffs_vars_dict = {str(k): v for k, v in coeffs_vars.items()}
data = assign_multiindex_safe(data, **coeffs_vars_dict)

# transpose with new Dataset to really ensure correct order
data = Dataset(data.transpose(..., TERM_DIM))
data = data.transpose(..., TERM_DIM)

# ensure helper dimensions are not set as coordinates
if drop_dims := set(HELPER_DIMS).intersection(data.coords):
Expand Down Expand Up @@ -2098,7 +2097,7 @@ def __init__(self, data: Dataset | None, model: Model) -> None:
raise ValueError(f"Size of dimension {FACTOR_DIM} must be 2.")

# transpose data to have _term as last dimension and _factor as second last
data = xr.Dataset(data.transpose(..., FACTOR_DIM, TERM_DIM))
data = data.transpose(..., FACTOR_DIM, TERM_DIM)
self._data = data

@property
Expand Down
4 changes: 3 additions & 1 deletion linopy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ def parameters(self, value: Dataset | Mapping) -> None:
"""
Set the parameters of the model.
"""
self._parameters = Dataset(value)
self._parameters = (
value.copy() if isinstance(value, Dataset) else Dataset(value)
)

@property
def solution(self) -> Dataset:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies = [
"bottleneck",
"toolz",
"numexpr",
"xarray>=2024.2.0,<2026.4",
"xarray>=2024.2.0",
"dask>=0.18.0",
"polars>=1.31.1",
"tqdm",
Expand Down
Loading