From 785ecaf1d4ff4823c6c34841150593e906ce7123 Mon Sep 17 00:00:00 2001 From: Nitish Bharambe Date: Mon, 8 Jul 2024 17:49:45 +0200 Subject: [PATCH] fix empty data auto id Signed-off-by: Nitish Bharambe --- .../converters/tabular_converter.py | 2 ++ tests/unit/converters/test_tabular_converter.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/power_grid_model_io/converters/tabular_converter.py b/src/power_grid_model_io/converters/tabular_converter.py index 349d559e..931080cb 100644 --- a/src/power_grid_model_io/converters/tabular_converter.py +++ b/src/power_grid_model_io/converters/tabular_converter.py @@ -626,6 +626,8 @@ def auto_id(row: np.ndarray): return pgm_id + if col_data.empty: + return col_data return col_data.apply(auto_id, axis=1, raw=True) def _parse_pandas_function( diff --git a/tests/unit/converters/test_tabular_converter.py b/tests/unit/converters/test_tabular_converter.py index b54950b9..43b7fb46 100644 --- a/tests/unit/converters/test_tabular_converter.py +++ b/tests/unit/converters/test_tabular_converter.py @@ -798,6 +798,22 @@ def test_parse_auto_id__invalid_key_definition( ) +@patch("power_grid_model_io.converters.tabular_converter.TabularConverter._get_id") +def test_parse_auto_id__empty_col_data( + mock_get_id: MagicMock, converter: TabularConverter, tabular_data_no_units_no_substitutions: TabularData +): + converter._parse_auto_id( + data=tabular_data_no_units_no_substitutions, + table="lines", + ref_table=None, + ref_name=None, + key_col_def={"id": "id_number", "node": "from_node_side"}, + table_mask=np.array([False, False]), + extra_info={}, + ) + mock_get_id.assert_not_called() + + @pytest.mark.parametrize( ("function", "expected"), [