Skip to content

Commit ac64741

Browse files
committed
fix representation of empty variables/linexpressions
1 parent 24a5772 commit ac64741

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

doc/release_notes.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
Release Notes
22
=============
33

4-
.. Upcoming Release
5-
.. ----------------
4+
Upcoming Release
5+
----------------
6+
7+
* Fix representation of empty variables and linear expressions.
68

79

810
Version 0.1.3

linopy/expressions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ def __repr__(self):
226226
truncate = nexprs > max_print
227227
coords = self.unravel_coords(to_print)
228228

229+
if not self.size:
230+
return f"{header}\nNone"
231+
229232
# loop over all values to print
230233
coord_strings = []
231234
expr_strings = []

linopy/variables.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ def __repr__(self):
229229
labels = np.ravel(self.labels.values)
230230
coords = [[c.item() for c in self.coords.values()]]
231231

232+
if not self.size:
233+
return f"{header}\nNone"
234+
232235
coord_strings = []
233236
var_strings = []
234237
bound_strings = []

test/test_repr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ def test_constraint_repr():
131131
repr(con)
132132

133133

134+
def test_empty_repr():
135+
repr(u.loc[[]])
136+
repr(lu.sel(dim_0=[]))
137+
repr(lu.sel(dim_0=[]) >= 0)
138+
139+
134140
def test_print_options():
135141
for o in [v, lv, cv_, cv]:
136142
default_repr = repr(o)

0 commit comments

Comments
 (0)