Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/columnar-data-examples' …
Browse files Browse the repository at this point in the history
…into feature/private-core-module

Signed-off-by: Martijn Govers <Martijn.Govers@Alliander.com>
  • Loading branch information
mgovers committed Oct 21, 2024
2 parents 0c7c82b + 19be23d commit 08da0c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 118 deletions.
5 changes: 4 additions & 1 deletion docs/examples/Power Flow Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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 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."
]
},
Expand All @@ -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",
Expand Down Expand Up @@ -487,7 +490,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."
]
},
{
Expand Down
120 changes: 3 additions & 117 deletions docs/examples/Serialization Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -637,69 +637,13 @@
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>id</th>\n",
" <th>u_rated</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>10500.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>10500.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>10500.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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])"
]
},
{
Expand All @@ -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": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>id</th>\n",
" <th>u_rated</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>10500.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>10500.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>10500.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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": [
Expand All @@ -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()))"
]
},
{
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/validation/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 08da0c8

Please sign in to comment.