Skip to content

Commit a2d0602

Browse files
committed
a few addition dataset types fixes
Signed-off-by: Santiago Figueroa Manrique <[email protected]>
1 parent 2948365 commit a2d0602

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

src/power_grid_model_io/converters/base_converter.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def load_input_data(
5555

5656
data = self._load_data(data)
5757
extra_info: ExtraInfo = {}
58-
parsed_data = self._parse_data(data=data, data_type="input", extra_info=extra_info if make_extra_info else None)
58+
parsed_data = self._parse_data(
59+
data=data, data_type=DatasetType.input, extra_info=extra_info if make_extra_info else None
60+
)
5961
if isinstance(parsed_data, list):
6062
raise TypeError("Input data can not be batch data")
6163
return parsed_data, extra_info
@@ -72,7 +74,7 @@ def load_update_data(self, data: Optional[T] = None) -> Dataset:
7274
7375
"""
7476
data = self._load_data(data)
75-
return self._parse_data(data=data, data_type="update", extra_info=None)
77+
return self._parse_data(data=data, data_type=DatasetType.update, extra_info=None)
7678

7779
def load_sym_output_data(self, data: Optional[T] = None) -> Dataset:
7880
"""Load symmetric output data
@@ -86,7 +88,7 @@ def load_sym_output_data(self, data: Optional[T] = None) -> Dataset:
8688
8789
"""
8890
data = self._load_data(data)
89-
return self._parse_data(data=data, data_type="sym_output", extra_info=None)
91+
return self._parse_data(data=data, data_type=DatasetType.sym_output, extra_info=None)
9092

9193
def load_asym_output_data(self, data: Optional[T] = None) -> Dataset:
9294
"""Load asymmetric output data
@@ -100,7 +102,7 @@ def load_asym_output_data(self, data: Optional[T] = None) -> Dataset:
100102
101103
"""
102104
data = self._load_data(data)
103-
return self._parse_data(data=data, data_type="asym_output", extra_info=None)
105+
return self._parse_data(data=data, data_type=DatasetType.asym_output, extra_info=None)
104106

105107
def load_sc_output_data(self, data: Optional[T] = None) -> Dataset:
106108
"""Load sc output data
@@ -114,7 +116,7 @@ def load_sc_output_data(self, data: Optional[T] = None) -> Dataset:
114116
115117
"""
116118
data = self._load_data(data)
117-
return self._parse_data(data=data, data_type="sc_output", extra_info=None)
119+
return self._parse_data(data=data, data_type=DatasetType.sc_output, extra_info=None)
118120

119121
def convert(self, data: Dataset, extra_info: Optional[ExtraInfo] = None) -> T:
120122
"""Convert input/update/(a)sym_output data and optionally extra info.

src/power_grid_model_io/converters/pandapower_converter.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _parse_data(
8686
Args:
8787
data: PandaPowerData, i.e. a dictionary with the components as keys and pd.DataFrames as values, with
8888
attribute names as columns and their values in the table
89-
data_type: power-grid-model data type, i.e. "input" or "update"
89+
data_type: power-grid-model data type, i.e. DatasetType.input or DatasetType.update
9090
extra_info: an optional dictionary where extra component info (that can't be specified in
9191
power-grid-model data) can be specified
9292
@@ -103,7 +103,7 @@ def _parse_data(
103103
self.pp_input_data = data
104104

105105
# Convert
106-
if data_type == "input":
106+
if data_type == DatasetType.input:
107107
self._create_input_data()
108108
else:
109109
raise ValueError(f"Data type: '{data_type}' is not implemented")
@@ -149,9 +149,9 @@ def pgm_output_dtype_checker(check_type: DatasetType | str) -> bool:
149149
)
150150

151151
# Convert
152-
if pgm_output_dtype_checker("sym_output"):
152+
if pgm_output_dtype_checker(DatasetType.sym_output):
153153
self._create_output_data()
154-
elif pgm_output_dtype_checker("asym_output"):
154+
elif pgm_output_dtype_checker(DatasetType.asym_output):
155155
self._create_output_data_3ph()
156156
else:
157157
raise TypeError("Invalid output data dictionary supplied.")

src/power_grid_model_io/converters/pgm_json_converter.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def _parse_data(self, data: StructuredData, data_type: DatasetType, extra_info:
6161
6262
Args:
6363
data: Structured data, which can either be a dictionary or a list of dictionaries
64-
data_type: the data type of the dataset, i.e. "input", "update", "sym_output" or "asym_output"
64+
data_type: the data type of the dataset, i.e. DatasetType.input, DatasetType.update,
65+
DatasetType.sym_output or DatasetType.asym_output
6566
extra_info: an optional dictionary where extra component info (that can't be specified in
6667
power-grid-model data) can be specified
6768
data: StructuredData:
@@ -70,7 +71,7 @@ def _parse_data(self, data: StructuredData, data_type: DatasetType, extra_info:
7071
7172
Returns:
7273
a dictionary containing the components as keys and their corresponding numpy arrays as values: a
73-
power-grid-model "input" or "update" dataset
74+
power-grid-model DatasetType.input or DatasetType.update dataset
7475
7576
"""
7677
self._log.debug(f"Loading PGM {data_type} data")
@@ -99,7 +100,7 @@ def _parse_dataset(
99100
100101
Args:
101102
data: a single Python dataset
102-
data_type: the data type of the dataset, i.e. "input" or "update"
103+
data_type: the data type of the dataset, i.e. DatasetType.input or DatasetType.update
103104
extra_info: an optional dictionary where extra component info (that can't be specified in
104105
power-grid-model data) can be specified
105106
data: SinglePythonDataset:
@@ -108,7 +109,7 @@ def _parse_dataset(
108109
109110
Returns:
110111
a dictionary containing the components as keys and their corresponding numpy arrays as values: a
111-
power-grid-model "input" or "update" dataset
112+
power-grid-model DatasetType.input or DatasetType.update dataset
112113
113114
"""
114115
return {
@@ -128,7 +129,7 @@ def _parse_component(
128129
objects: a list with dictionaries, where each dictionary contains all attributes of a component
129130
component: the type of component, eg. node, line, etc. Note: it should be a valid power-grid-model
130131
component
131-
data_type: a string specifying the data type: input/update
132+
data_type: a string specifying the data type: DatasetType.input/DatasetType.update
132133
extra_info: an optional dictionary where extra component info (that can't be specified in
133134
power-grid-model data) can be specified
134135
objects: ComponentList:

src/power_grid_model_io/converters/tabular_converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _parse_data(self, data: TabularData, data_type: DatasetType, extra_info: Opt
9696
Args:
9797
data: TabularData, i.e. a dictionary with the components as keys and pd.DataFrames as values, with
9898
attribute names as columns and their values in the table
99-
data_type: power-grid-model data type, i.e. "input" or "update"
99+
data_type: power-grid-model data type, i.e. DatasetType.input or DatasetType.update
100100
extra_info: an optional dictionary where extra component info (that can't be specified in
101101
power-grid-model data) can be specified
102102
data: TabularData:
@@ -158,7 +158,7 @@ def _convert_table_to_component( # pylint: disable = too-many-arguments,too-man
158158
159159
Args:
160160
data: The full dataset with tabular data
161-
data_type: The data type, i.e. "input" or "update"
161+
data_type: The data type, i.e. DatasetType.input or DatasetType.update
162162
table: The name of the table that should be converter
163163
component: the component for which a power-grid-model array should be made
164164
attributes: a dictionary with a mapping from the attribute names in the table to the corresponding

tests/unit/converters/test_tabular_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def test_convert_table_to_component__filters(
180180
}
181181
converter._convert_table_to_component(
182182
data=tabular_data_no_units_no_substitutions,
183-
data_type="input",
183+
data_type=DatasetType.input,
184184
table="nodes",
185185
component=ComponentType.node,
186186
attributes=node_attributes_with_filter,

tests/validation/test_test_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import numpy as np
99
import pandas as pd
10-
from power_grid_model import ComponentType, power_grid_meta_data
10+
from power_grid_model import ComponentType, DatasetType, power_grid_meta_data
1111

1212
from .utils import component_attributes, extract_extra_info, select_values
1313

@@ -17,7 +17,7 @@
1717
@patch("pathlib.Path.open", mock_open(read_data=MOCK_JSON_DATA))
1818
def test_component_attributes():
1919
# Act
20-
generator = component_attributes(Path("test.json"), data_type="input")
20+
generator = component_attributes(Path("test.json"), data_type=DatasetType.input)
2121

2222
# Assert
2323
assert list(generator) == [
@@ -30,7 +30,7 @@ def test_component_attributes():
3030

3131
def test_select_values():
3232
# Arrange
33-
input_node_dtype = power_grid_meta_data["input"][ComponentType.node].dtype
33+
input_node_dtype = power_grid_meta_data[DatasetType.input][ComponentType.node].dtype
3434
actual = {ComponentType.node: np.array([(2, 2.0), (4, np.nan), (3, 3.0), (1, 1.0)], dtype=input_node_dtype)}
3535
expected = {ComponentType.node: np.array([(4, 4.0), (1, np.nan), (3, 3.0)], dtype=input_node_dtype)}
3636

@@ -52,7 +52,7 @@ def test_extract_extra_info():
5252
}
5353

5454
# Act
55-
extra_info = extract_extra_info(data=data, data_type="input")
55+
extra_info = extract_extra_info(data=data, data_type=DatasetType.input)
5656

5757
# Assert
5858
assert extra_info[1] == {"name": "bar"}

0 commit comments

Comments
 (0)