From c3d4f028a790e67cf7600a2cbf3af04101b471b0 Mon Sep 17 00:00:00 2001 From: nader-00 Date: Wed, 5 Aug 2026 13:49:12 +0200 Subject: [PATCH 1/2] fix(pypsa_io): include line shunt susceptance in per-grid to_pypsa export The mv/lv per-grid export path dropped the "b" column from lines_df while the full-grid path (mode=None) kept it, so PyPSA silently defaulted it to 0 instead of the real value on the per-grid path. Align both paths to select the same Line columns, and add a regression test that injects a distinguishing non-zero b to catch the divergence (issue #654). --- edisgo/io/pypsa_io.py | 2 +- tests/io/test_pypsa_io.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/edisgo/io/pypsa_io.py b/edisgo/io/pypsa_io.py index 9e9135687..94d5006c9 100755 --- a/edisgo/io/pypsa_io.py +++ b/edisgo/io/pypsa_io.py @@ -486,7 +486,7 @@ def _get_grid_component_dict(grid_object): ], "Line": grid_object.lines_df.loc[ :, - ["bus0", "bus1", "x", "r", "s_nom", "num_parallel", "length"], + ["bus0", "bus1", "x", "r", "b", "s_nom", "num_parallel", "length"], ], } return components diff --git a/tests/io/test_pypsa_io.py b/tests/io/test_pypsa_io.py index 14246f3e9..9534dd3b8 100644 --- a/tests/io/test_pypsa_io.py +++ b/tests/io/test_pypsa_io.py @@ -33,6 +33,36 @@ def test_to_pypsa(self): assert len(pypsa_network.buses) == 15 # ToDo: Check further things and parameter options + def test_to_pypsa_line_b_column_consistent_across_modes(self): + # the full-grid path (mode=None) and the per-grid paths (mode="mv" and + # mode="lv") used to select different Line columns from lines_df, with + # the per-grid paths silently dropping "b" (see GitHub issue #654). + # Since "b" is always zero in eDisGo grids today, that regressed + # silently, so set a distinguishing non-zero value here to catch it. + self.edisgo = EDisGo(ding0_grid=pytest.ding0_test_network_path) + self.edisgo.set_time_series_worst_case_analysis() + timeindex = self.edisgo.timeseries.timeindex + + mv_grid = self.edisgo.topology.mv_grid + lv_grid = self.edisgo.topology.get_lv_grid(1) + mv_line = mv_grid.lines_df.index[0] + lv_line = lv_grid.lines_df.index[0] + self.edisgo.topology.lines_df.loc[mv_line, "b"] = 1.234e-5 + self.edisgo.topology.lines_df.loc[lv_line, "b"] = 5.678e-5 + + pypsa_network_full = pypsa_io.to_pypsa(self.edisgo, timesteps=timeindex) + pypsa_network_mv = pypsa_io.to_pypsa( + self.edisgo, timesteps=timeindex, mode="mv" + ) + pypsa_network_lv = pypsa_io.to_pypsa( + self.edisgo, timesteps=timeindex, mode="lv", lv_grid_id=lv_grid.id + ) + + assert pypsa_network_full.lines.loc[mv_line, "b"] == 1.234e-5 + assert pypsa_network_full.lines.loc[lv_line, "b"] == 5.678e-5 + assert pypsa_network_mv.lines.loc[mv_line, "b"] == 1.234e-5 + assert pypsa_network_lv.lines.loc[lv_line, "b"] == 5.678e-5 + def test_append_lv_components(self): lv_components = { "Load": pd.DataFrame(), From 048bef4ea08353f02e4c07c37a6ffc5649752eeb Mon Sep 17 00:00:00 2001 From: nader-00 Date: Tue, 11 Aug 2026 10:07:54 +0200 Subject: [PATCH 2/2] test: update enhanced_reinforce_grid golden counts after Line b fix --- tests/test_edisgo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_edisgo.py b/tests/test_edisgo.py index 9847cc7a1..d345773b5 100755 --- a/tests/test_edisgo.py +++ b/tests/test_edisgo.py @@ -583,8 +583,8 @@ def test_enhanced_reinforce_grid(self): results = edisgo_obj.results - assert len(results.grid_expansion_costs) == 454 - assert len(results.equipment_changes) == 892 + assert len(results.grid_expansion_costs) == 453 + assert len(results.equipment_changes) == 835 assert results.v_res.shape == (4, 148) edisgo_obj = copy.deepcopy(self.edisgo)