Skip to content

Commit

Permalink
add release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianHofmann committed Dec 5, 2024
1 parent 37d720b commit 507d205
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Release Notes
Upcoming Version
----------------

* When creating slices for variables and constraints (important for the `solve` function), the slicing is now fixed in case now dimension to slice is available.
* Added a pandas priority attribute. With this change, the operation with pandas objects is now prioritizing linopy objects over pandas objects. This is useful when the using linopy objects in arithmetic operations with pandas objects, e.g. `a * x` where `a` is a pandas Series/DataFrame and `x` is a linopy variable.
* The method :meth:`model.to_file <linopy.model.Model.to_file>` now includes a progress argument to enable or disable the progress bar while writing.

Expand Down
4 changes: 4 additions & 0 deletions linopy/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,10 @@ def iterate_slices(

# leading dimension (the dimension with the largest size)
sizes = {dim: ds.sizes[dim] for dim in slice_dims}
if not sizes:
yield ds
return

leading_dim = max(sizes, key=sizes.get) # type: ignore
size_of_leading_dim = ds.sizes[leading_dim]

Expand Down
14 changes: 11 additions & 3 deletions test/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,14 +522,22 @@ def test_iterate_slices_slice_size_none():
assert ds.equals(s)


def test_iterate_slices_invalid_slice_dims():
def test_iterate_slices_empty_slice_dims():
ds = xr.Dataset(
{"var": (("x", "y"), np.random.rand(10, 10))}, # noqa: NPY002
coords={"x": np.arange(10), "y": np.arange(10)},
)
with pytest.raises(ValueError):
list(iterate_slices(ds, slice_size=50, slice_dims=[]))
slices = list(iterate_slices(ds, slice_size=50, slice_dims=[]))
assert len(slices) == 1
for s in slices:
assert ds.equals(s)


def test_iterate_slices_invalid_slice_dims():
ds = xr.Dataset(
{"var": (("x", "y"), np.random.rand(10, 10))}, # noqa: NPY002
coords={"x": np.arange(10), "y": np.arange(10)},
)
with pytest.raises(ValueError):
list(iterate_slices(ds, slice_size=50, slice_dims=["z"]))

Expand Down

0 comments on commit 507d205

Please sign in to comment.