Skip to content

Commit

Permalink
fix empty data auto id
Browse files Browse the repository at this point in the history
Signed-off-by: Nitish Bharambe <nitish.bharambe@alliander.com>
  • Loading branch information
nitbharambe committed Jul 8, 2024
1 parent ccc6089 commit 785ecaf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/power_grid_model_io/converters/tabular_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/converters/test_tabular_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
[
Expand Down

0 comments on commit 785ecaf

Please sign in to comment.