From 88849d0bacad34b33aeb21cdc832a1ed323d41f8 Mon Sep 17 00:00:00 2001 From: Thijs Baaijen <13253091+Thijss@users.noreply.github.com> Date: Wed, 4 Mar 2026 10:21:14 +0100 Subject: [PATCH] Avoid empty input arrays Signed-off-by: Thijs Baaijen <13253091+Thijss@users.noreply.github.com> --- .../_core/power_grid_model_interface.py | 4 +++- tests/unit/model/grids/serialization/test_json.py | 7 ++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/power_grid_model_ds/_core/power_grid_model_interface.py b/src/power_grid_model_ds/_core/power_grid_model_interface.py index 93712e37..26ca6319 100644 --- a/src/power_grid_model_ds/_core/power_grid_model_interface.py +++ b/src/power_grid_model_ds/_core/power_grid_model_interface.py @@ -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: diff --git a/tests/unit/model/grids/serialization/test_json.py b/tests/unit/model/grids/serialization/test_json.py index 866150a5..294bdaa0 100644 --- a/tests/unit/model/grids/serialization/test_json.py +++ b/tests/unit/model/grids/serialization/test_json.py @@ -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")) - 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