Skip to content

Commit

Permalink
Merge branch 'main' into feature/allow-clipped-i0
Browse files Browse the repository at this point in the history
  • Loading branch information
mgovers authored Aug 21, 2024
2 parents 98535e3 + 2f566ef commit 8432d1d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build-test-and-sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ["3.9", "3.10", "3.11", "3.12"]
python: ["3.10", "3.11", "3.12"]
exclude:
- os: macos-latest
python: "3.9"
python: "3.10"
fail-fast: false
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -131,10 +131,10 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ["3.9", "3.10", "3.11", "3.12"]
python: ["3.10", "3.11", "3.12"]
exclude:
- os: macos-latest
python: "3.9"
python: "3.10"
fail-fast: false
runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sphinx:
build:
os: "ubuntu-20.04"
tools:
python: "3.9"
python: "3.10"
jobs:
post_install:
# Build package with doc requirements from pyproject.optional-dependencies
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers=[
"Operating System :: MacOS",
"Topic :: Scientific/Engineering :: Physics",
]
requires-python = ">=3.9"
requires-python = ">=3.10"
dependencies = [
"numpy>=1.20",
"openpyxl",
Expand Down Expand Up @@ -84,7 +84,7 @@ addopts = ["--cov=power_grid_model_io", "--cov-report=term", "--cov-report=html:

[tool.black]
line-length = 120
target-version = ["py39", "py310", "py311"]
target-version = ["py310", "py311"]

[tool.isort]
profile = "black"
Expand Down
4 changes: 4 additions & 0 deletions src/power_grid_model_io/converters/tabular_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ def _convert_table_to_component(

if "filters" in attributes:
table_mask = self._parse_table_filters(data=data, table=table, filtering_functions=attributes["filters"])
if table_mask is not None and not table_mask.any():
return None
else:
table_mask = None

Expand Down Expand Up @@ -626,6 +628,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
49 changes: 45 additions & 4 deletions tests/unit/converters/test_tabular_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ def tabular_data():
)
lines = pd.DataFrame(data=[[1, 100], [2, 200]], columns=["id_number", "from_node_side"])
loads = pd.DataFrame(data=[[1, 1, 1], [2, 2, 0]], columns=["id_number", "node_id", "switching_status"])
tabular_data = TabularData(nodes=nodes, lines=lines, loads=loads)
return tabular_data
sources = pd.DataFrame(columns=["id_number", "node_side"])
return TabularData(nodes=nodes, lines=lines, loads=loads, sources=sources)


@pytest.fixture
def tabular_data_no_units_no_substitutions():
nodes = pd.DataFrame(data=[[1, 10.5e3], [2, 400.0]], columns=["id_number", "u_nom"])
lines = pd.DataFrame(data=[[1, 2], [3, 1]], columns=["id_number", "from_node_side"])
tabular_data = TabularData(nodes=nodes, lines=lines)
return tabular_data
sources = pd.DataFrame(columns=["id_number", "node_side"])
return TabularData(nodes=nodes, lines=lines, sources=sources)


def test_set_mapping_file(converter: TabularConverter):
Expand Down Expand Up @@ -175,6 +175,31 @@ def test_convert_table_to_component__filters(
)


def test_convert_table_to_component__filters_all_false(
converter: TabularConverter, tabular_data_no_units_no_substitutions: TabularData
):
converter._convert_col_def_to_attribute = MagicMock()
converter._parse_table_filters = MagicMock()
converter._parse_table_filters.side_effect = np.array([False, False])
node_attributes_with_filter = {"id": "id_number", "u_rated": "u_nom", "filters": [{"test_fn": {}}]}
actual = converter._convert_table_to_component(
data=tabular_data_no_units_no_substitutions,
data_type="input",
table="nodes",
component="node",
attributes=node_attributes_with_filter,
extra_info=None,
)

assert actual is None
converter._parse_table_filters.assert_called_once_with(
data=tabular_data_no_units_no_substitutions,
table="nodes",
filtering_functions=node_attributes_with_filter["filters"],
)
converter._convert_col_def_to_attribute.assert_not_called()


def test_convert_col_def_to_attribute(
converter: TabularConverter,
tabular_data_no_units_no_substitutions: TabularData,
Expand Down Expand Up @@ -798,6 +823,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 8432d1d

Please sign in to comment.