From e9e79956b5f695839ccad55238b5274b659a88e8 Mon Sep 17 00:00:00 2001 From: Martijn Govers Date: Mon, 21 Oct 2024 13:12:18 +0200 Subject: [PATCH 1/4] more code coverage Signed-off-by: Martijn Govers --- tests/unit/validation/test_errors.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/unit/validation/test_errors.py b/tests/unit/validation/test_errors.py index f4c980399..bb76d64bc 100644 --- a/tests/unit/validation/test_errors.py +++ b/tests/unit/validation/test_errors.py @@ -88,6 +88,22 @@ def test_invalid_id_error(): assert str(error) == "Field 'november' does not contain a valid oscar/papa id for 3 nodes." +def test_invalid_id_error_with_filters(): + error = InvalidIdError( + ComponentType.node, + field="november", + ids=[1, 2, 3], + ref_components=["oscar", "papa"], + filters={"foo": "bar", "baz": ComponentType.node}, + ) + assert error.component == "node" + assert error.field == "november" + assert error.ids == [1, 2, 3] + assert error.ref_components == ["oscar", "papa"] + assert error.filters_str == "(foo=bar, baz=node)" + assert str(error) == "Field 'november' does not contain a valid oscar/papa id for 3 nodes. (foo=bar, baz=node)" + + def test_comparison_error(): error = ComparisonError(component=ComponentType.node, field="romeo", ids=[1, 2, 3], ref_value=0) assert error.component == "node" From 8220bc7166376f6ef82d56900444343b0e2264d2 Mon Sep 17 00:00:00 2001 From: Martijn Govers Date: Mon, 21 Oct 2024 15:11:17 +0200 Subject: [PATCH 2/4] process comments Signed-off-by: Martijn Govers --- docs/examples/Power Flow Example.ipynb | 4 +- docs/examples/Serialization Example.ipynb | 120 +--------------------- 2 files changed, 5 insertions(+), 119 deletions(-) diff --git a/docs/examples/Power Flow Example.ipynb b/docs/examples/Power Flow Example.ipynb index da1e83956..dcb198358 100644 --- a/docs/examples/Power Flow Example.ipynb +++ b/docs/examples/Power Flow Example.ipynb @@ -435,7 +435,7 @@ "\n", "* `None` requests row-based data\n", "* a list of attribute names requests columns for those attributes (as before)\n", - "* `ComponentAttributeFilterOptions.ALL` requests columns for all supported attributes of a component." + "* `ComponentAttributeFilterOptions.everything` requests columns for all supported attributes of a component." ] }, { @@ -487,7 +487,7 @@ "id": "14a34c07", "metadata": {}, "source": [ - "Finally, it is possible to request columnar data for all attributes using the `ComponentAttributeFilterOptions.ALL` as a shorthand." + "Finally, it is possible to request columnar data for all attributes using the `ComponentAttributeFilterOptions.everything` as a shorthand." ] }, { diff --git a/docs/examples/Serialization Example.ipynb b/docs/examples/Serialization Example.ipynb index a964cd557..b718946da 100644 --- a/docs/examples/Serialization Example.ipynb +++ b/docs/examples/Serialization Example.ipynb @@ -637,69 +637,13 @@ }, "metadata": {}, "output_type": "display_data" - }, - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
idu_rated
0110500.0
1210500.0
2310500.0
\n", - "
" - ], - "text/plain": [ - " id u_rated\n", - "0 1 10500.0\n", - "1 2 10500.0\n", - "2 3 10500.0" - ] - }, - "metadata": {}, - "output_type": "display_data" } ], "source": [ "dataset = json_deserialize(data, data_filter=ComponentAttributeFilterOptions.everything)\n", "\n", "print(\"components:\", list(dataset.keys()))\n", - "display(dataset[ComponentType.node])\n", - "display(DataFrame(dataset[ComponentType.node]))" + "display(dataset[ComponentType.node])" ] }, { @@ -724,64 +668,8 @@ "node attributes: ['id', 'u_rated']\n", "source attributes: ['id', 'node', 'status', 'u_ref', 'sk']\n", "sym_load attributes: ['id', 'node', 'status', 'type', 'p_specified', 'q_specified']\n", - "line attributes: ['id', 'from_node', 'to_node', 'from_status', 'to_status', 'r1', 'x1', 'c1', 'tan1', 'i_n']\n", - "-------node data-------\n" + "line attributes: ['id', 'from_node', 'to_node', 'from_status', 'to_status', 'r1', 'x1', 'c1', 'tan1', 'i_n']\n" ] - }, - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
idu_rated
0110500.0
1210500.0
2310500.0
\n", - "
" - ], - "text/plain": [ - " id u_rated\n", - "0 1 10500.0\n", - "1 2 10500.0\n", - "2 3 10500.0" - ] - }, - "metadata": {}, - "output_type": "display_data" } ], "source": [ @@ -799,9 +687,7 @@ "print(\"node attributes:\", list(dataset[ComponentType.node].dtype.names))\n", "print(\"source attributes:\", list(dataset[ComponentType.source].keys()))\n", "print(\"sym_load attributes:\", list(dataset[ComponentType.sym_load].keys()))\n", - "print(\"line attributes:\", list(dataset[ComponentType.line].keys()))\n", - "print(\"-------node data-------\")\n", - "display(DataFrame(dataset[ComponentType.node]))" + "print(\"line attributes:\", list(dataset[ComponentType.line].keys()))" ] }, { From 313834a6f1d04e8eaf5d7e1ffbae85260a3b463c Mon Sep 17 00:00:00 2001 From: Martijn Govers Date: Mon, 21 Oct 2024 15:19:30 +0200 Subject: [PATCH 3/4] minor elaboration on columnar data Signed-off-by: Martijn Govers --- docs/examples/Power Flow Example.ipynb | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/examples/Power Flow Example.ipynb b/docs/examples/Power Flow Example.ipynb index dcb198358..ab6830ebf 100644 --- a/docs/examples/Power Flow Example.ipynb +++ b/docs/examples/Power Flow Example.ipynb @@ -129,6 +129,8 @@ "source": [ "It is also possible to specify a component input data in a columnar data format.\n", "\n", + "A columnar data format allows better integration with existing databases. In addition, it may bring memory and, in some cases, even computational performance improvements, because unused attribute columns can be omitted.\n", + "\n", "Make sure to provide the correct `dtype` to the numpy arrays, exposed for each dataset type, component and attribute via the `power_grid_meta_data` object." ] }, @@ -145,6 +147,7 @@ " \"node\": np.array([1], dtype=source_attribute_dtypes[\"node\"]),\n", " \"status\": np.array([1], dtype=source_attribute_dtypes[\"status\"]),\n", " \"u_ref\": np.array([1.0], dtype=source_attribute_dtypes[\"u_ref\"]),\n", + " # We're not creating columns for u_ref_angle, sk, ... Instead, the default values are used. This saves us memory.\n", "}\n", "\n", "input_data = {\n", @@ -1346,16 +1349,16 @@ "output_type": "stream", "text": [ "Node data with invalid results\n", - "[[0.99940117 0.99268579 0.99452137]\n", - " [0.99934769 0.98622639 0.98935286]\n", - " [0.99928838 0.97965401 0.98409554]\n", - " [0. 0. 0. ]\n", - " [0.99915138 0.96614948 0.97329879]\n", - " [0.99907317 0.95920586 0.96775071]\n", - " [0.9989881 0.95212621 0.96209647]\n", - " [0. 0. 0. ]\n", - " [0.99879613 0.93753005 0.95044796]\n", - " [0.9986885 0.92999747 0.94444167]]\n", + "[[9.99401170e-001 9.92685785e-001 9.94521366e-001]\n", + " [9.99347687e-001 9.86226389e-001 9.89352855e-001]\n", + " [9.99288384e-001 9.79654011e-001 9.84095542e-001]\n", + " [6.01347174e-154 7.39986091e-038 6.55490955e-260]\n", + " [9.99151380e-001 9.66149483e-001 9.73298790e-001]\n", + " [9.99073166e-001 9.59205860e-001 9.67750710e-001]\n", + " [9.98988099e-001 9.52126208e-001 9.62096474e-001]\n", + " [6.95195146e-310 6.95195146e-310 6.95195146e-310]\n", + " [9.98796126e-001 9.37530046e-001 9.50447962e-001]\n", + " [9.98688504e-001 9.29997471e-001 9.44441670e-001]]\n", "Node data with only valid results\n", "[[0.99940117 0.99268579 0.99452137]\n", " [0.99934769 0.98622639 0.98935286]\n", From 19be23d2e1fb0845782525f92415246617bb2a4a Mon Sep 17 00:00:00 2001 From: Martijn Govers Date: Mon, 21 Oct 2024 15:20:05 +0200 Subject: [PATCH 4/4] minor elaboration on columnar data Signed-off-by: Martijn Govers --- docs/examples/Power Flow Example.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/examples/Power Flow Example.ipynb b/docs/examples/Power Flow Example.ipynb index ab6830ebf..251332de1 100644 --- a/docs/examples/Power Flow Example.ipynb +++ b/docs/examples/Power Flow Example.ipynb @@ -129,7 +129,7 @@ "source": [ "It is also possible to specify a component input data in a columnar data format.\n", "\n", - "A columnar data format allows better integration with existing databases. In addition, it may bring memory and, in some cases, even computational performance improvements, because unused attribute columns can be omitted.\n", + "A columnar data format better integrates with most databases. In addition, it may bring memory and, in some cases, even computational performance improvements, because unused attribute columns can be omitted.\n", "\n", "Make sure to provide the correct `dtype` to the numpy arrays, exposed for each dataset type, component and attribute via the `power_grid_meta_data` object." ] @@ -1352,11 +1352,11 @@ "[[9.99401170e-001 9.92685785e-001 9.94521366e-001]\n", " [9.99347687e-001 9.86226389e-001 9.89352855e-001]\n", " [9.99288384e-001 9.79654011e-001 9.84095542e-001]\n", - " [6.01347174e-154 7.39986091e-038 6.55490955e-260]\n", + " [0.00000000e+000 3.04369633e+101 3.41345331e+241]\n", " [9.99151380e-001 9.66149483e-001 9.73298790e-001]\n", " [9.99073166e-001 9.59205860e-001 9.67750710e-001]\n", " [9.98988099e-001 9.52126208e-001 9.62096474e-001]\n", - " [6.95195146e-310 6.95195146e-310 6.95195146e-310]\n", + " [1.66994188e-321 3.12878333e-312 9.75772002e+199]\n", " [9.98796126e-001 9.37530046e-001 9.50447962e-001]\n", " [9.98688504e-001 9.29997471e-001 9.44441670e-001]]\n", "Node data with only valid results\n",