Skip to content

Commit 8697d7b

Browse files
committed
more files
Signed-off-by: Thijs Baaijen <[email protected]>
1 parent b7761bb commit 8697d7b

File tree

6 files changed

+75
-75
lines changed

6 files changed

+75
-75
lines changed

src/power_grid_model_ds/_core/data_source/generator/arrays/transformer.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ def run(self, amount: int) -> TransformerArray:
1717
"""Generate transformers"""
1818

1919
# Create transformers from 10kV to 3kV
20-
from_mask = self.grid.node.u_rated == 10_500
21-
from_nodes = self.rng.choice(self.grid.node.id[from_mask], amount, replace=True)
22-
to_mask = self.grid.node.u_rated == 3_000
23-
to_nodes = self.rng.choice(self.grid.node.id[to_mask], amount, replace=False)
20+
from_mask = self.grid.node["u_rated"] == 10_500
21+
from_nodes = self.rng.choice(self.grid.node["id"][from_mask], amount, replace=True)
22+
to_mask = self.grid.node["u_rated"] == 3_000
23+
to_nodes = self.rng.choice(self.grid.node["id"][to_mask], amount, replace=False)
2424
transformer_array = self.grid.transformer.__class__.zeros(amount)
25-
transformer_array.id = 1 + self.grid.max_id + np.arange(amount)
26-
transformer_array.from_node = from_nodes
27-
transformer_array.to_node = to_nodes
28-
transformer_array.from_status = [1] * amount
29-
transformer_array.to_status = [1] * amount
30-
transformer_array.u1 = [10_500] * amount
31-
transformer_array.u2 = [3_000] * amount
32-
transformer_array.sn = [30e6] * amount
33-
transformer_array.clock = [12] * amount
34-
transformer_array.uk = [0.203] * amount
35-
transformer_array.pk = [100e3] * amount
25+
transformer_array["id"] = 1 + self.grid.max_id + np.arange(amount)
26+
transformer_array["from_node"] = from_nodes
27+
transformer_array["to_node"] = to_nodes
28+
transformer_array["from_status"] = [1] * amount
29+
transformer_array["to_status"] = [1] * amount
30+
transformer_array["u1"] = [10_500] * amount
31+
transformer_array["u2"] = [3_000] * amount
32+
transformer_array["sn"] = [30e6] * amount
33+
transformer_array["clock"] = [12] * amount
34+
transformer_array["uk"] = [0.203] * amount
35+
transformer_array["pk"] = [100e3] * amount
3636

3737
return transformer_array

tests/integration/loadflow/test_power_grid_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def test_batch_run(self):
165165
core_interface = PowerGridModelInterface(grid=grid)
166166

167167
update_sym_load = initialize_array("update", "sym_load", (10, len(grid.sym_load)))
168-
update_sym_load["id"] = [grid.sym_load.id.tolist()]
168+
update_sym_load["id"] = [grid.sym_load["id"].tolist()]
169169
update_sym_load["p_specified"] = [grid.sym_load.p_specified.tolist()] * np.linspace(0, 1, 10).reshape(-1, 1)
170170
update_sym_load["q_specified"] = [grid.sym_load.q_specified.tolist()] * np.linspace(0, 1, 10).reshape(-1, 1)
171171
update_data = {

tests/integration/visualizer_tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def get_radial_grid() -> Grid:
2222
def get_coordinated_grid() -> CoordinatedGrid:
2323
scale = 500
2424
grid = CoordinatedGrid.from_txt("S1 2 open", "2 3", "3 4", "S1 500000000", "500000000 6", "6 7 transformer")
25-
grid.node.x = [3, 2.5, 2, 1.5, 3.5, 4, 4.5]
26-
grid.node.x *= scale
27-
grid.node.y = [3, 4, 3, 4, 3, 4, 3]
28-
grid.node.y *= scale
25+
grid.node["x"] = [3, 2.5, 2, 1.5, 3.5, 4, 4.5]
26+
grid.node["x"] *= scale
27+
grid.node["y"] = [3, 4, 3, 4, 3, 4, 3]
28+
grid.node["y"] *= scale
2929
return grid
3030

3131

tests/unit/model/arrays/test_modify.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414

1515
class TestReorder:
1616
def test_reorder_by_id(self, fancy_test_array: FancyTestArray):
17-
assert_array_equal(fancy_test_array.id, [1, 2, 3])
18-
assert_array_equal(fancy_test_array.test_str, ["a", "c", "d"])
17+
assert_array_equal(fancy_test_array["id"], [1, 2, 3])
18+
assert_array_equal(fancy_test_array["test_str"], ["a", "c", "d"])
1919
reordered = fancy_test_array.re_order([3, 1, 2])
20-
assert_array_equal(reordered.id, [3, 1, 2])
21-
assert_array_equal(reordered.test_str, ["d", "a", "c"])
20+
assert_array_equal(reordered["id"], [3, 1, 2])
21+
assert_array_equal(reordered["test_str"], ["d", "a", "c"])
2222

2323
def test_reorder_by_test_str(self, fancy_test_array: FancyTestArray):
24-
assert_array_equal(fancy_test_array.id, [1, 2, 3])
25-
assert_array_equal(fancy_test_array.test_str, ["a", "c", "d"])
24+
assert_array_equal(fancy_test_array["id"], [1, 2, 3])
25+
assert_array_equal(fancy_test_array["test_str"], ["a", "c", "d"])
2626
reordered = fancy_test_array.re_order(["d", "a", "c"], column="test_str")
27-
assert_array_equal(reordered.id, [3, 1, 2])
28-
assert_array_equal(reordered.test_str, ["d", "a", "c"])
27+
assert_array_equal(reordered["id"], [3, 1, 2])
28+
assert_array_equal(reordered["test_str"], ["d", "a", "c"])
2929

3030
def test_reorder_mismatched_length(self, fancy_test_array: FancyTestArray):
3131
with pytest.raises(ValueError):
@@ -34,30 +34,30 @@ def test_reorder_mismatched_length(self, fancy_test_array: FancyTestArray):
3434

3535
class TestUpdateById:
3636
def test_get_update_by_id(self, fancy_test_array: FancyTestArray):
37-
assert_array_equal(fancy_test_array.id, [1, 2, 3])
38-
assert_array_equal(fancy_test_array.test_str, ["a", "c", "d"])
37+
assert_array_equal(fancy_test_array["id"], [1, 2, 3])
38+
assert_array_equal(fancy_test_array["test_str"], ["a", "c", "d"])
3939
updated = fancy_test_array.get_updated_by_id([1, 3], test_str="e")
4040

41-
assert_array_equal(updated.id, [1, 3])
42-
assert_array_equal(updated.test_str, ["e", "e"])
41+
assert_array_equal(updated["id"], [1, 3])
42+
assert_array_equal(updated["test_str"], ["e", "e"])
4343

44-
assert_array_equal(fancy_test_array.id, [1, 2, 3])
45-
assert_array_equal(fancy_test_array.test_str, ["e", "c", "e"])
44+
assert_array_equal(fancy_test_array["id"], [1, 2, 3])
45+
assert_array_equal(fancy_test_array["test_str"], ["e", "c", "e"])
4646

4747
def test_get_update_by_id_duplicate_id_input(self, fancy_test_array: FancyTestArray):
48-
assert_array_equal(fancy_test_array.id, [1, 2, 3])
49-
assert_array_equal(fancy_test_array.test_str, ["a", "c", "d"])
48+
assert_array_equal(fancy_test_array["id"], [1, 2, 3])
49+
assert_array_equal(fancy_test_array["test_str"], ["a", "c", "d"])
5050
updated = fancy_test_array.get_updated_by_id([1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3], test_str="e")
5151

52-
assert_array_equal(updated.id, [1, 3])
52+
assert_array_equal(updated["id"], [1, 3])
5353

5454
def test_update_by_id_multiple_columns(self, fancy_test_array: FancyTestArray):
55-
assert_array_equal(fancy_test_array.id, [1, 2, 3])
56-
assert_array_equal(fancy_test_array.test_str, ["a", "c", "d"])
55+
assert_array_equal(fancy_test_array["id"], [1, 2, 3])
56+
assert_array_equal(fancy_test_array["test_str"], ["a", "c", "d"])
5757
fancy_test_array.update_by_id([1, 3], test_str="e", test_int=[88, 99])
58-
assert_array_equal(fancy_test_array.id, [1, 2, 3])
59-
assert_array_equal(fancy_test_array.test_str, ["e", "c", "e"])
60-
assert_array_equal(fancy_test_array.test_int, [88, 0, 99])
58+
assert_array_equal(fancy_test_array["id"], [1, 2, 3])
59+
assert_array_equal(fancy_test_array["test_str"], ["e", "c", "e"])
60+
assert_array_equal(fancy_test_array["test_int"], [88, 0, 99])
6161

6262
def test_update_by_id_invalid_column(self, fancy_test_array: FancyTestArray):
6363
with pytest.raises(ValueError):
@@ -73,7 +73,7 @@ def test_update_by_id_invalid_id(self, fancy_test_array: FancyTestArray):
7373

7474
def test_update_by_id_invalid_id_allow_missing(self, fancy_test_array: FancyTestArray):
7575
fancy_test_array.update_by_id([1, 4], test_str="e", allow_missing=True)
76-
assert fancy_test_array.get(1).record.test_str == "e"
76+
assert fancy_test_array.get(1)["test_str"] == "e"
7777

7878
def test_update_by_id_no_id_column(self):
7979
fancy_non_id_array = FancyNonIdArray.zeros(10)
@@ -87,11 +87,11 @@ def test_update_by_id_non_existing_id(self, fancy_test_array: FancyTestArray):
8787

8888
class TestConcatenate:
8989
def test_concatenate_fancy_array(self, fancy_test_array: FancyTestArray):
90-
assert_array_equal(fancy_test_array.id, [1, 2, 3])
91-
assert_array_equal(fancy_test_array.test_str, ["a", "c", "d"])
90+
assert_array_equal(fancy_test_array["id"], [1, 2, 3])
91+
assert_array_equal(fancy_test_array["test_str"], ["a", "c", "d"])
9292
concatenated = fp.concatenate(fancy_test_array, fancy_test_array)
93-
assert_array_equal(concatenated.id, [1, 2, 3, 1, 2, 3])
94-
assert_array_equal(concatenated.test_str, ["a", "c", "d", "a", "c", "d"])
93+
assert_array_equal(concatenated["id"], [1, 2, 3, 1, 2, 3])
94+
assert_array_equal(concatenated["test_str"], ["a", "c", "d", "a", "c", "d"])
9595

9696
def test_concatenate_to_empty_array(self, fancy_test_array: FancyTestArray):
9797
empty_array = FancyTestArray()
@@ -104,18 +104,18 @@ def test_concatenate_empty_arrays(self):
104104
assert concatenated.size == 0
105105

106106
def test_concatenate_multiple_fancy_arrays(self, fancy_test_array: FancyTestArray):
107-
assert_array_equal(fancy_test_array.id, [1, 2, 3])
108-
assert_array_equal(fancy_test_array.test_str, ["a", "c", "d"])
107+
assert_array_equal(fancy_test_array["id"], [1, 2, 3])
108+
assert_array_equal(fancy_test_array["test_str"], ["a", "c", "d"])
109109
concatenated = fp.concatenate(fancy_test_array, fancy_test_array, fancy_test_array)
110-
assert_array_equal(concatenated.id, [1, 2, 3, 1, 2, 3, 1, 2, 3])
111-
assert_array_equal(concatenated.test_str, ["a", "c", "d", "a", "c", "d", "a", "c", "d"])
110+
assert_array_equal(concatenated["id"], [1, 2, 3, 1, 2, 3, 1, 2, 3])
111+
assert_array_equal(concatenated["test_str"], ["a", "c", "d", "a", "c", "d", "a", "c", "d"])
112112

113113
def test_concatenate_ndarray(self, fancy_test_array: FancyTestArray):
114-
assert_array_equal(fancy_test_array.id, [1, 2, 3])
115-
assert_array_equal(fancy_test_array.test_str, ["a", "c", "d"])
114+
assert_array_equal(fancy_test_array["id"], [1, 2, 3])
115+
assert_array_equal(fancy_test_array["test_str"], ["a", "c", "d"])
116116
concatenated = fp.concatenate(fancy_test_array, fancy_test_array.data)
117-
assert_array_equal(concatenated.id, [1, 2, 3, 1, 2, 3])
118-
assert_array_equal(concatenated.test_str, ["a", "c", "d", "a", "c", "d"])
117+
assert_array_equal(concatenated["id"], [1, 2, 3, 1, 2, 3])
118+
assert_array_equal(concatenated["test_str"], ["a", "c", "d", "a", "c", "d"])
119119

120120
def test_concatenate_different_fancy_array(self, fancy_test_array: FancyTestArray):
121121
different_array = FancyNonIdArray.zeros(10)
@@ -131,7 +131,7 @@ def test_concatenate_different_fancy_array_same_dtype(self, fancy_test_array: Fa
131131
sub_array = fancy_test_array[["test_str", "test_int"]]
132132

133133
different_array = FancyNonIdArray.zeros(10)
134-
different_sub_array = different_array[["test_str", "test_int"]]
134+
different_sub_array = different_array.data[["test_str", "test_int"]]
135135

136136
concatenated = np.concatenate([sub_array, different_sub_array])
137137
assert concatenated.size == 13

tests/unit/model/arrays/test_pgm_arrays.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313
@pytest.fixture(name="branches")
1414
def parallel_branches():
1515
branches = BranchArray.zeros(3)
16-
branches.from_node = [0, 0, 1]
17-
branches.to_node = [1, 1, 2]
16+
branches["from_node"] = [0, 0, 1]
17+
branches["to_node"] = [1, 1, 2]
1818
return branches
1919

2020

2121
class TestBranchArray:
2222
def test_branch_is_active(self):
2323
branches = BranchArray.zeros(4)
24-
branches.from_status = [1, 1, 0, 0]
25-
branches.to_status = [1, 0, 1, 0]
24+
branches["from_status"] = [1, 1, 0, 0]
25+
branches["to_status"] = [1, 0, 1, 0]
2626

2727
assert_array_equal(branches.is_active, [True, False, False, False])
2828
assert branches[0].is_active
2929

3030
def test_branch_node_ids(self):
3131
branches = BranchArray.zeros(2)
32-
branches.from_node = [0, 1]
33-
branches.to_node = [1, 2]
32+
branches["from_node"] = [0, 1]
33+
branches["to_node"] = [1, 2]
3434

3535
assert_array_equal(branches.node_ids, [0, 1, 1, 2])
3636

@@ -58,10 +58,10 @@ def test_as_branches_single(self):
5858

5959
assert branch_array.size == 3
6060

61-
assert branch_array.from_node.tolist() == [1, 1, 2]
62-
assert branch_array.to_node.tolist() == [2, 3, 3]
63-
assert branch_array.from_status.tolist() == [1, 1, 1]
64-
assert branch_array.to_status.tolist() == [1, 0, 0]
61+
assert branch_array["from_node"].tolist() == [1, 1, 2]
62+
assert branch_array["to_node"].tolist() == [2, 3, 3]
63+
assert branch_array["from_status"].tolist() == [1, 1, 1]
64+
assert branch_array["to_status"].tolist() == [1, 0, 0]
6565

6666
def test_as_branches_multiple(self):
6767
branch3 = Branch3Array(
@@ -77,7 +77,7 @@ def test_as_branches_multiple(self):
7777
branch_array.sort(order=["from_node", "to_node"])
7878

7979
assert branch_array.size == 6
80-
assert branch_array.from_node.tolist() == [1, 1, 2, 4, 4, 5]
81-
assert branch_array.to_node.tolist() == [2, 3, 3, 5, 6, 6]
82-
assert branch_array.from_status.tolist() == [1, 1, 1, 1, 1, 1]
83-
assert branch_array.to_status.tolist() == [1, 1, 1, 1, 0, 0]
80+
assert branch_array["from_node"].tolist() == [1, 1, 2, 4, 4, 5]
81+
assert branch_array["to_node"].tolist() == [2, 3, 3, 5, 6, 6]
82+
assert branch_array["from_status"].tolist() == [1, 1, 1, 1, 1, 1]
83+
assert branch_array["to_status"].tolist() == [1, 1, 1, 1, 0, 0]

tests/unit/model/arrays/test_string.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_str_empty_array():
2424

2525
def test_str_large_array():
2626
array = FancyTestArray.zeros(100)
27-
array.test_str = "ABC"
27+
array["test_str"] = "ABC"
2828
array_str = str(array)
2929

3030
splits = array_str.replace("\n", "|").split("|")
@@ -44,8 +44,8 @@ def test_str_long_column_name():
4444

4545
def test_str_long_values():
4646
array = FancyTestArray.zeros(1)
47-
array.test_str = "this_is_a_very_long_value"
48-
array.test_int = 112233445566778899
47+
array["test_str"] = "this_is_a_very_long_value"
48+
array["test_int"] = 112233445566778899
4949
array_str = array.as_table(column_width=15)
5050

5151
splits = array_str.replace("\n", "|").split("|")
@@ -63,8 +63,8 @@ def test_str_long_column_name_autosize():
6363

6464
def test_str_long_values_autosize():
6565
array = FancyTestArray.zeros(1)
66-
array.test_str = "this_is_a_very_long_value"
67-
array.test_int = 112233445566778899
66+
array["test_str"] = "this_is_a_very_long_value"
67+
array["test_int"] = 112233445566778899
6868
array_str = str(array)
6969
assert "| this_is_a_very_long_value" in array_str
7070
assert "| 112233445566778899" in array_str

0 commit comments

Comments
 (0)