Skip to content

Commit 648bf24

Browse files
FBumannclaude
andcommitted
feat: show user dims with sizes in PiecewiseFormulation header
Match Constraint repr style: `name` [dim: size, ...] — method Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 91188b9 commit 648bf24

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

linopy/piecewise.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,18 @@ class PiecewiseFormulation:
7777
constraints: Constraints
7878

7979
def __repr__(self) -> str:
80-
r = f"PiecewiseFormulation `{self.name}` — {self.method}\n"
80+
# Collect user-facing dims with sizes (skip internal _ prefixed dims)
81+
user_dims: dict[str, int] = {}
82+
for var in self.variables.data.values():
83+
for d in var.coords:
84+
ds = str(d)
85+
if not ds.startswith("_") and ds not in user_dims:
86+
user_dims[ds] = var.data.sizes[d]
87+
dims_str = ", ".join(f"{d}: {s}" for d, s in user_dims.items())
88+
header = f"PiecewiseFormulation `{self.name}`"
89+
if dims_str:
90+
header += f" [{dims_str}]"
91+
r = f"{header}{self.method}\n"
8192
r += " Variables:\n"
8293
for vname, var in self.variables.items():
8394
dims = ", ".join(str(d) for d in var.coords) if var.coords else ""

0 commit comments

Comments
 (0)