Skip to content
Draft
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
4 changes: 3 additions & 1 deletion src/power_grid_model_ds/_core/power_grid_model_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ def create_input_from_grid(self):
"""
Create input for the PowerGridModel
"""
self._input_data = {}
for array_name in ComponentType:
if not hasattr(self.grid, array_name):
continue
pgm_array = self._create_power_grid_array(array_name=array_name)
self._input_data[array_name] = pgm_array
if pgm_array.size > 0:
self._input_data[array_name] = pgm_array
return self._input_data

def create_grid_from_input_data(self, check_ids: bool = True) -> Grid:
Expand Down
7 changes: 2 additions & 5 deletions tests/unit/model/grids/serialization/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,9 @@ def test_serialization_roundtrip(self, request, grid_fixture: str, tmp_path: Pat
loaded_grid = Grid.deserialize(path)
assert loaded_grid == grid

@pytest.mark.parametrize("grid_fixture", ("basic_grid", "grid"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason we should test on grid anymore?

def test_pgm_roundtrip(self, request, grid_fixture: str, tmp_path: Path):
def test_pgm_roundtrip(self, basic_grid: Grid, tmp_path: Path):
"""Test roundtrip serialization for PGM-compatible grid"""
# Grid
grid: Grid = request.getfixturevalue(grid_fixture)

grid = basic_grid
# Replace nan values with dummy value. Otherwise PGM's json_serialize_to_file will remove these columns.
grid.node.u_rated = 42

Expand Down