Skip to content

Commit 8432d1d

Browse files
authored
Merge branch 'main' into feature/allow-clipped-i0
2 parents 98535e3 + 2f566ef commit 8432d1d

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

.github/workflows/build-test-and-sonar.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ jobs:
9797
strategy:
9898
matrix:
9999
os: [ubuntu-latest, macos-latest, windows-latest]
100-
python: ["3.9", "3.10", "3.11", "3.12"]
100+
python: ["3.10", "3.11", "3.12"]
101101
exclude:
102102
- os: macos-latest
103-
python: "3.9"
103+
python: "3.10"
104104
fail-fast: false
105105
runs-on: ${{ matrix.os }}
106106

@@ -131,10 +131,10 @@ jobs:
131131
strategy:
132132
matrix:
133133
os: [ubuntu-latest, macos-latest, windows-latest]
134-
python: ["3.9", "3.10", "3.11", "3.12"]
134+
python: ["3.10", "3.11", "3.12"]
135135
exclude:
136136
- os: macos-latest
137-
python: "3.9"
137+
python: "3.10"
138138
fail-fast: false
139139
runs-on: ${{ matrix.os }}
140140

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ sphinx:
1111
build:
1212
os: "ubuntu-20.04"
1313
tools:
14-
python: "3.9"
14+
python: "3.10"
1515
jobs:
1616
post_install:
1717
# Build package with doc requirements from pyproject.optional-dependencies

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ classifiers=[
2626
"Operating System :: MacOS",
2727
"Topic :: Scientific/Engineering :: Physics",
2828
]
29-
requires-python = ">=3.9"
29+
requires-python = ">=3.10"
3030
dependencies = [
3131
"numpy>=1.20",
3232
"openpyxl",
@@ -84,7 +84,7 @@ addopts = ["--cov=power_grid_model_io", "--cov-report=term", "--cov-report=html:
8484

8585
[tool.black]
8686
line-length = 120
87-
target-version = ["py39", "py310", "py311"]
87+
target-version = ["py310", "py311"]
8888

8989
[tool.isort]
9090
profile = "black"

src/power_grid_model_io/converters/tabular_converter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ def _convert_table_to_component(
180180

181181
if "filters" in attributes:
182182
table_mask = self._parse_table_filters(data=data, table=table, filtering_functions=attributes["filters"])
183+
if table_mask is not None and not table_mask.any():
184+
return None
183185
else:
184186
table_mask = None
185187

@@ -626,6 +628,8 @@ def auto_id(row: np.ndarray):
626628

627629
return pgm_id
628630

631+
if col_data.empty:
632+
return col_data
629633
return col_data.apply(auto_id, axis=1, raw=True)
630634

631635
def _parse_pandas_function(

tests/unit/converters/test_tabular_converter.py

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ def tabular_data():
5151
)
5252
lines = pd.DataFrame(data=[[1, 100], [2, 200]], columns=["id_number", "from_node_side"])
5353
loads = pd.DataFrame(data=[[1, 1, 1], [2, 2, 0]], columns=["id_number", "node_id", "switching_status"])
54-
tabular_data = TabularData(nodes=nodes, lines=lines, loads=loads)
55-
return tabular_data
54+
sources = pd.DataFrame(columns=["id_number", "node_side"])
55+
return TabularData(nodes=nodes, lines=lines, loads=loads, sources=sources)
5656

5757

5858
@pytest.fixture
5959
def tabular_data_no_units_no_substitutions():
6060
nodes = pd.DataFrame(data=[[1, 10.5e3], [2, 400.0]], columns=["id_number", "u_nom"])
6161
lines = pd.DataFrame(data=[[1, 2], [3, 1]], columns=["id_number", "from_node_side"])
62-
tabular_data = TabularData(nodes=nodes, lines=lines)
63-
return tabular_data
62+
sources = pd.DataFrame(columns=["id_number", "node_side"])
63+
return TabularData(nodes=nodes, lines=lines, sources=sources)
6464

6565

6666
def test_set_mapping_file(converter: TabularConverter):
@@ -175,6 +175,31 @@ def test_convert_table_to_component__filters(
175175
)
176176

177177

178+
def test_convert_table_to_component__filters_all_false(
179+
converter: TabularConverter, tabular_data_no_units_no_substitutions: TabularData
180+
):
181+
converter._convert_col_def_to_attribute = MagicMock()
182+
converter._parse_table_filters = MagicMock()
183+
converter._parse_table_filters.side_effect = np.array([False, False])
184+
node_attributes_with_filter = {"id": "id_number", "u_rated": "u_nom", "filters": [{"test_fn": {}}]}
185+
actual = converter._convert_table_to_component(
186+
data=tabular_data_no_units_no_substitutions,
187+
data_type="input",
188+
table="nodes",
189+
component="node",
190+
attributes=node_attributes_with_filter,
191+
extra_info=None,
192+
)
193+
194+
assert actual is None
195+
converter._parse_table_filters.assert_called_once_with(
196+
data=tabular_data_no_units_no_substitutions,
197+
table="nodes",
198+
filtering_functions=node_attributes_with_filter["filters"],
199+
)
200+
converter._convert_col_def_to_attribute.assert_not_called()
201+
202+
178203
def test_convert_col_def_to_attribute(
179204
converter: TabularConverter,
180205
tabular_data_no_units_no_substitutions: TabularData,
@@ -798,6 +823,22 @@ def test_parse_auto_id__invalid_key_definition(
798823
)
799824

800825

826+
@patch("power_grid_model_io.converters.tabular_converter.TabularConverter._get_id")
827+
def test_parse_auto_id__empty_col_data(
828+
mock_get_id: MagicMock, converter: TabularConverter, tabular_data_no_units_no_substitutions: TabularData
829+
):
830+
converter._parse_auto_id(
831+
data=tabular_data_no_units_no_substitutions,
832+
table="lines",
833+
ref_table=None,
834+
ref_name=None,
835+
key_col_def={"id": "id_number", "node": "from_node_side"},
836+
table_mask=np.array([False, False]),
837+
extra_info={},
838+
)
839+
mock_get_id.assert_not_called()
840+
841+
801842
@pytest.mark.parametrize(
802843
("function", "expected"),
803844
[

0 commit comments

Comments
 (0)