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
6 changes: 4 additions & 2 deletions docs/examples/model/grid_extensions_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
"source": [
"## Adding the new arrays to the Grid\n",
"\n",
"When these arrays have been defined they should also be provided to the Grid object.\n"
"When these arrays have been defined they should also be provided to the Grid object.\n",
"\n",
"We advise to use `repr=False` with the dataclass wrapper, to get our grid representation function instead of the default dataclass one. "
]
},
{
Expand All @@ -65,7 +67,7 @@
"from power_grid_model_ds import GraphContainer, Grid\n",
"\n",
"\n",
"@dataclass\n",
"@dataclass(repr=False)\n",
"class ExtendedGrid(Grid):\n",
" \"\"\"\n",
" This is my own grid to extend.\n",
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/grid_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class UserDefinedArray(FancyArray):
_defaults: ClassVar[dict[str, int]] = {"branch_id": 42, "node_id": 43}


@dataclass
@dataclass(repr=False)
class ExtendedGrid(Grid):
"""ExtendedGrid class for testing purposes."""

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


@dataclass
@dataclass(repr=False)
class ExtendedGridNoDefaults(Grid):
node: CustomNodeArray
line: CustomLineArray
4 changes: 3 additions & 1 deletion tests/unit/model/grids/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def test_basic_grid_fixture(basic_grid: Grid):
assert len(grid.line) + len(grid.transformer) + len(grid.link) == grid.graphs.complete_graph.nr_branches


def test_repr_includes_graph_and_arrays(basic_grid: Grid):
@pytest.mark.parametrize("grid_class", [Grid, ExtendedGrid])
def test_repr_includes_graph_and_arrays(grid_class: type[Grid]):
basic_grid = build_basic_grid(grid_class.empty())
repr_str = repr(basic_grid)

assert "graphs=GraphContainer(" in repr_str
Expand Down