Skip to content

Commit db231b8

Browse files
docs: add note on repr use (#268)
Signed-off-by: Vincent Koppen <vincent.koppen@alliander.com>
1 parent 0e0ddb6 commit db231b8

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

docs/examples/model/grid_extensions_examples.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
"source": [
5252
"## Adding the new arrays to the Grid\n",
5353
"\n",
54-
"When these arrays have been defined they should also be provided to the Grid object.\n"
54+
"When these arrays have been defined they should also be provided to the Grid object.\n",
55+
"\n",
56+
"We advise to use `repr=False` with the dataclass wrapper, to get our grid representation function instead of the default dataclass one. "
5557
]
5658
},
5759
{
@@ -65,7 +67,7 @@
6567
"from power_grid_model_ds import GraphContainer, Grid\n",
6668
"\n",
6769
"\n",
68-
"@dataclass\n",
70+
"@dataclass(repr=False)\n",
6971
"class ExtendedGrid(Grid):\n",
7072
" \"\"\"\n",
7173
" This is my own grid to extend.\n",

tests/fixtures/grid_classes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class UserDefinedArray(FancyArray):
2323
_defaults: ClassVar[dict[str, int]] = {"branch_id": 42, "node_id": 43}
2424

2525

26-
@dataclass
26+
@dataclass(repr=False)
2727
class ExtendedGrid(Grid):
2828
"""ExtendedGrid class for testing purposes."""
2929

@@ -33,7 +33,7 @@ class ExtendedGrid(Grid):
3333
extra_value: int = 123
3434

3535

36-
@dataclass
36+
@dataclass(repr=False)
3737
class ExtendedGridNoDefaults(Grid):
3838
node: CustomNodeArray
3939
line: CustomLineArray

tests/unit/model/grids/test_base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ def test_basic_grid_fixture(basic_grid: Grid):
8383
assert len(grid.line) + len(grid.transformer) + len(grid.link) == grid.graphs.complete_graph.nr_branches
8484

8585

86-
def test_repr_includes_graph_and_arrays(basic_grid: Grid):
86+
@pytest.mark.parametrize("grid_class", [Grid, ExtendedGrid])
87+
def test_repr_includes_graph_and_arrays(grid_class: type[Grid]):
88+
basic_grid = build_basic_grid(grid_class.empty())
8789
repr_str = repr(basic_grid)
8890

8991
assert "graphs=GraphContainer(" in repr_str

0 commit comments

Comments
 (0)