power-grid-model-io 1.2.14__py3-none-any.whl → 1.2.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of power-grid-model-io might be problematic. Click here for more details.
- power_grid_model_io/data_types/tabular_data.py +21 -8
- {power_grid_model_io-1.2.14.dist-info → power_grid_model_io-1.2.15.dist-info}/METADATA +5 -5
- {power_grid_model_io-1.2.14.dist-info → power_grid_model_io-1.2.15.dist-info}/RECORD +6 -6
- {power_grid_model_io-1.2.14.dist-info → power_grid_model_io-1.2.15.dist-info}/LICENSE +0 -0
- {power_grid_model_io-1.2.14.dist-info → power_grid_model_io-1.2.15.dist-info}/WHEEL +0 -0
- {power_grid_model_io-1.2.14.dist-info → power_grid_model_io-1.2.15.dist-info}/top_level.txt +0 -0
|
@@ -6,7 +6,7 @@ The TabularData class is a wrapper around Dict[str, Union[pd.DataFrame, np.ndarr
|
|
|
6
6
|
which supports unit conversions and value substitutions
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
-
from typing import Dict, Iterable, Optional, Tuple, Union
|
|
9
|
+
from typing import Callable, Dict, Generator, Iterable, Optional, Tuple, Union
|
|
10
10
|
|
|
11
11
|
import numpy as np
|
|
12
12
|
import pandas as pd
|
|
@@ -15,6 +15,8 @@ import structlog
|
|
|
15
15
|
from power_grid_model_io.mappings.unit_mapping import UnitMapping
|
|
16
16
|
from power_grid_model_io.mappings.value_mapping import ValueMapping
|
|
17
17
|
|
|
18
|
+
LazyDataFrame = Callable[[], pd.DataFrame]
|
|
19
|
+
|
|
18
20
|
|
|
19
21
|
class TabularData:
|
|
20
22
|
"""
|
|
@@ -22,7 +24,7 @@ class TabularData:
|
|
|
22
24
|
which supports unit conversions and value substitutions
|
|
23
25
|
"""
|
|
24
26
|
|
|
25
|
-
def __init__(self, **tables: Union[pd.DataFrame, np.ndarray]):
|
|
27
|
+
def __init__(self, **tables: Union[pd.DataFrame, np.ndarray, LazyDataFrame]):
|
|
26
28
|
"""
|
|
27
29
|
Tabular data can either be a collection of pandas DataFrames and/or numpy structured arrays.
|
|
28
30
|
The key word arguments will define the keys of the data.
|
|
@@ -34,12 +36,12 @@ class TabularData:
|
|
|
34
36
|
**tables: A collection of pandas DataFrames and/or numpy structured arrays
|
|
35
37
|
"""
|
|
36
38
|
for table_name, table_data in tables.items():
|
|
37
|
-
if not isinstance(table_data, (pd.DataFrame, np.ndarray)):
|
|
39
|
+
if not isinstance(table_data, (pd.DataFrame, np.ndarray)) and not callable(table_data):
|
|
38
40
|
raise TypeError(
|
|
39
41
|
f"Invalid data type for table '{table_name}'; "
|
|
40
42
|
f"expected a pandas DataFrame or NumPy array, got {type(table_data).__name__}."
|
|
41
43
|
)
|
|
42
|
-
self._data: Dict[str, Union[pd.DataFrame, np.ndarray]] = tables
|
|
44
|
+
self._data: Dict[str, Union[pd.DataFrame, np.ndarray, LazyDataFrame]] = tables
|
|
43
45
|
self._units: Optional[UnitMapping] = None
|
|
44
46
|
self._substitution: Optional[ValueMapping] = None
|
|
45
47
|
self._log = structlog.get_logger(type(self).__name__)
|
|
@@ -73,7 +75,7 @@ class TabularData:
|
|
|
73
75
|
Returns:
|
|
74
76
|
The required column, with unit conversions and value substitutions applied
|
|
75
77
|
"""
|
|
76
|
-
table_data = self
|
|
78
|
+
table_data = self[table_name]
|
|
77
79
|
|
|
78
80
|
# If the index 'column' is requested, but no column called 'index' exist,
|
|
79
81
|
# return the index of the dataframe as if it were an actual column.
|
|
@@ -154,6 +156,14 @@ class TabularData:
|
|
|
154
156
|
|
|
155
157
|
return table_data[pd.MultiIndex.from_tuples([(field, si_unit)])[0]]
|
|
156
158
|
|
|
159
|
+
def __len__(self) -> int:
|
|
160
|
+
"""
|
|
161
|
+
Return the number of tables (regardless of if they are already loaded or not)
|
|
162
|
+
|
|
163
|
+
Returns: The number of tables
|
|
164
|
+
"""
|
|
165
|
+
return len(self._data)
|
|
166
|
+
|
|
157
167
|
def __contains__(self, table_name: str) -> bool:
|
|
158
168
|
"""
|
|
159
169
|
Mimic the dictionary 'in' operator
|
|
@@ -176,6 +186,8 @@ class TabularData:
|
|
|
176
186
|
|
|
177
187
|
Returns: The 'raw' table data
|
|
178
188
|
"""
|
|
189
|
+
if callable(self._data[table_name]):
|
|
190
|
+
self._data[table_name] = self._data[table_name]()
|
|
179
191
|
return self._data[table_name]
|
|
180
192
|
|
|
181
193
|
def keys(self) -> Iterable[str]:
|
|
@@ -187,13 +199,14 @@ class TabularData:
|
|
|
187
199
|
|
|
188
200
|
return self._data.keys()
|
|
189
201
|
|
|
190
|
-
def items(self) ->
|
|
202
|
+
def items(self) -> Generator[Tuple[str, Union[pd.DataFrame, np.ndarray]], None, None]:
|
|
191
203
|
"""
|
|
192
204
|
Mimic the dictionary .items() function
|
|
193
205
|
|
|
194
|
-
Returns: An
|
|
206
|
+
Returns: An generator of the table names and the raw table data
|
|
195
207
|
"""
|
|
196
208
|
|
|
197
209
|
# Note: PyCharm complains about the type, but it is correct, as an ItemsView extends from
|
|
198
210
|
# AbstractSet[Tuple[_KT_co, _VT_co]], which actually is compatible with Iterable[_KT_co, _VT_co]
|
|
199
|
-
|
|
211
|
+
for key in self._data:
|
|
212
|
+
yield key, self[key]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: power-grid-model-io
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.15
|
|
4
4
|
Summary: Power Grid Model Input/Output
|
|
5
5
|
Author-email: Alliander Dynamic Grid Calculation <dynamic.grid.calculation@alliander.com>
|
|
6
6
|
License: MPL-2.0
|
|
@@ -67,15 +67,15 @@ SPDX-License-Identifier: MPL-2.0
|
|
|
67
67
|
For detailed documentation, see [Read the Docs](https://power-grid-model-io.readthedocs.io/en/stable/index.html).
|
|
68
68
|
|
|
69
69
|
# Examples
|
|
70
|
-
* [PGM JSON Example](https://github.com/alliander-opensource/power-grid-model-io/blob/
|
|
70
|
+
* [PGM JSON Example](https://github.com/alliander-opensource/power-grid-model-io/blob/7e498b3c2d5ca4581628587d9474c1efca004ea7/docs/examples/pgm_json_example.ipynb)
|
|
71
71
|
|
|
72
72
|
|
|
73
73
|
# License
|
|
74
|
-
This project is licensed under the Mozilla Public License, version 2.0 - see [LICENSE](https://github.com/alliander-opensource/power-grid-model-io/blob/
|
|
74
|
+
This project is licensed under the Mozilla Public License, version 2.0 - see [LICENSE](https://github.com/alliander-opensource/power-grid-model-io/blob/7e498b3c2d5ca4581628587d9474c1efca004ea7/LICENSE) for details.
|
|
75
75
|
|
|
76
76
|
# Contributing
|
|
77
|
-
Please read [CODE_OF_CONDUCT](https://github.com/alliander-opensource/power-grid-model-io/blob/
|
|
77
|
+
Please read [CODE_OF_CONDUCT](https://github.com/alliander-opensource/power-grid-model-io/blob/7e498b3c2d5ca4581628587d9474c1efca004ea7/CODE_OF_CONDUCT.md) and [CONTRIBUTING](https://github.com/alliander-opensource/power-grid-model-io/blob/7e498b3c2d5ca4581628587d9474c1efca004ea7/CONTRIBUTING.md) for details on the process
|
|
78
78
|
for submitting pull requests to us.
|
|
79
79
|
|
|
80
80
|
# Contact
|
|
81
|
-
Please read [SUPPORT](https://github.com/alliander-opensource/power-grid-model-io/blob/
|
|
81
|
+
Please read [SUPPORT](https://github.com/alliander-opensource/power-grid-model-io/blob/7e498b3c2d5ca4581628587d9474c1efca004ea7/SUPPORT.md) for how to connect and get into contact with the Power Gird Model IO project.
|
|
@@ -17,7 +17,7 @@ power_grid_model_io/data_stores/json_file_store.py,sha256=vmo25AiCIy16HDF8S5ZZKu
|
|
|
17
17
|
power_grid_model_io/data_stores/vision_excel_file_store.py,sha256=d5J6ClvIpef_JwKcqCilzYU411IR8Zju6R9Dc4j0KXQ,821
|
|
18
18
|
power_grid_model_io/data_types/__init__.py,sha256=zXc0yGSyNFxpORWjXnejEkvjXFZXXyfEO7PeUtoqWnA,384
|
|
19
19
|
power_grid_model_io/data_types/_data_types.py,sha256=IRQomW3ecETvIYfIzQRPDOwUY-TAa4g4mV17TvQVeGg,1834
|
|
20
|
-
power_grid_model_io/data_types/tabular_data.py,sha256=
|
|
20
|
+
power_grid_model_io/data_types/tabular_data.py,sha256=BC20WzbV1V03KD_BmfxwDKH4X_X_sbQ97PuUXz2Y7wA,8356
|
|
21
21
|
power_grid_model_io/functions/__init__.py,sha256=LQKpnYqnZhMHb9QwWTTGiMadwl3e6jMSEzJf6TlIZk0,511
|
|
22
22
|
power_grid_model_io/functions/_functions.py,sha256=J0KiqU_V3lniwNvYbFhF2_iOz5ug9_KahtlnM1xyeHs,2873
|
|
23
23
|
power_grid_model_io/functions/phase_to_phase.py,sha256=oaDRoPg6okII0rq8klPM085DF5pSmIDqlSiY9l-L5E8,6296
|
|
@@ -33,8 +33,8 @@ power_grid_model_io/utils/dict.py,sha256=Y5fCB22qIwFVHinUq-TO1eXeNWU177sVPyOVVaA
|
|
|
33
33
|
power_grid_model_io/utils/json.py,sha256=Fw9GhCiwk4sXw48ljPOkWAR0LaRkdA8ZkUQu-K0z0vU,3343
|
|
34
34
|
power_grid_model_io/utils/modules.py,sha256=ZB8IIK96VuJk5FkoclrUCuXOSsGeVqT3B01bBAcodeU,944
|
|
35
35
|
power_grid_model_io/utils/regex.py,sha256=0uJDRSfggmDFu_nip1Oge8NUXBQ_8e-3HTLdB8niAkQ,1728
|
|
36
|
-
power_grid_model_io-1.2.
|
|
37
|
-
power_grid_model_io-1.2.
|
|
38
|
-
power_grid_model_io-1.2.
|
|
39
|
-
power_grid_model_io-1.2.
|
|
40
|
-
power_grid_model_io-1.2.
|
|
36
|
+
power_grid_model_io-1.2.15.dist-info/LICENSE,sha256=7Pm2fWFFHHUG5lDHed1vl5CjzxObIXQglnYsEdtjo_k,14907
|
|
37
|
+
power_grid_model_io-1.2.15.dist-info/METADATA,sha256=vehvfqpJuj38lsYHOVfbt79N66zNAjWA3y-rxNCVjJ8,5679
|
|
38
|
+
power_grid_model_io-1.2.15.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
|
39
|
+
power_grid_model_io-1.2.15.dist-info/top_level.txt,sha256=7sq9VveemMm2R0RgTBa4tH8y_xF4_1hxbufmX9OjCTo,20
|
|
40
|
+
power_grid_model_io-1.2.15.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|