From 76fb98c9c7028e79e2702cd7285e76857bcc30b2 Mon Sep 17 00:00:00 2001 From: Martijn Govers Date: Mon, 30 Sep 2024 10:58:13 +0200 Subject: [PATCH 1/2] attempt fix pylint Signed-off-by: Martijn Govers --- .github/workflows/check-code-quality.yml | 1 - .pre-commit-config.yaml | 8 +- set_pypi_version.py | 3 +- .../converters/tabular_converter.py | 132 ++++++++++++++---- .../converters/vision_excel_converter.py | 4 +- .../functions/phase_to_phase.py | 2 +- 6 files changed, 113 insertions(+), 37 deletions(-) diff --git a/.github/workflows/check-code-quality.yml b/.github/workflows/check-code-quality.yml index f7000d8c..d18012a7 100644 --- a/.github/workflows/check-code-quality.yml +++ b/.github/workflows/check-code-quality.yml @@ -56,7 +56,6 @@ jobs: - name: If needed raise error run: | - if [[ `git status --porcelain --untracked-files=no` ]]; then echo "Formatting not correct! See below the files which need to be reformatted!" git status --porcelain --untracked-files=no diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6e15ecde..fcda58a6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,19 +4,19 @@ repos: - repo: https://github.com/fsfe/reuse-tool - rev: v3.0.1 + rev: v4.0.3 hooks: - id: reuse - repo: https://github.com/pycqa/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 24.8.0 hooks: - id: black-jupyter - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.2.0 + rev: v1.11.2 hooks: - id: mypy additional_dependencies: [numpy, pandas] diff --git a/set_pypi_version.py b/set_pypi_version.py index 47ce2b78..73de0dbe 100644 --- a/set_pypi_version.py +++ b/set_pypi_version.py @@ -8,6 +8,7 @@ import os from pathlib import Path +from typing import cast import requests @@ -43,7 +44,7 @@ def set_version(pkg_dir: Path): def get_pypi_latest(): request = requests.get("https://pypi.org/pypi/power-grid-model-io/json") data = request.json() - version: str = data["info"]["version"] + version = str(data["info"]["version"]) return (int(x) for x in version.split(".")) diff --git a/src/power_grid_model_io/converters/tabular_converter.py b/src/power_grid_model_io/converters/tabular_converter.py index 97941903..81b20515 100644 --- a/src/power_grid_model_io/converters/tabular_converter.py +++ b/src/power_grid_model_io/converters/tabular_converter.py @@ -4,6 +4,7 @@ """ Tabular Data Converter: Load data from multiple tables and use a mapping file to convert the data to PGM """ + import inspect import logging from pathlib import Path @@ -141,8 +142,7 @@ def _parse_data(self, data: TabularData, data_type: str, extra_info: Optional[Ex ) return input_data - # pylint: disable = too-many-arguments - def _convert_table_to_component( + def _convert_table_to_component( # pylint: disable = too-many-arguments,too-many-positional-arguments self, data: TabularData, data_type: str, @@ -197,7 +197,10 @@ def _convert_table_to_component( # Make sure that the "id" column is always parsed first (at least before "extra" is parsed) attributes_without_filter = {k: v for k, v in attributes.items() if k != "filters"} - sorted_attributes = sorted(attributes_without_filter.items(), key=lambda x: "" if x[0] == "id" else x[0]) + sorted_attributes = sorted( + attributes_without_filter.items(), + key=lambda x: "" if x[0] == "id" else x[0], + ) for attr, col_def in sorted_attributes: self._convert_col_def_to_attribute( @@ -224,8 +227,7 @@ def _parse_table_filters(self, data: TabularData, table: str, filtering_function table_mask &= cast(pd.DataFrame, data[table]).apply(fn_ptr, axis=1, **kwargs).values return table_mask - # pylint: disable = too-many-arguments - def _convert_col_def_to_attribute( + def _convert_col_def_to_attribute( # pylint: disable = too-many-arguments,too-many-positional-arguments self, data: TabularData, pgm_data: np.ndarray, @@ -282,7 +284,11 @@ def _convert_col_def_to_attribute( return attr_data = self._parse_col_def( - data=data, table=table, table_mask=table_mask, col_def=col_def, extra_info=extra_info + data=data, + table=table, + table_mask=table_mask, + col_def=col_def, + extra_info=extra_info, ) if len(attr_data.columns) != 1: @@ -290,7 +296,7 @@ def _convert_col_def_to_attribute( pgm_data[attr] = attr_data.iloc[:, 0] - def _handle_extra_info( + def _handle_extra_info( # pylint: disable = too-many-arguments,too-many-positional-arguments self, data: TabularData, table: str, @@ -322,7 +328,11 @@ def _handle_extra_info( return extra = self._parse_col_def( - data=data, table=table, table_mask=table_mask, col_def=col_def, extra_info=None + data=data, + table=table, + table_mask=table_mask, + col_def=col_def, + extra_info=None, ).to_dict(orient="records") for i, xtr in zip(uuids, extra): xtr = { @@ -369,7 +379,7 @@ def _serialize_data(self, data: Dataset, extra_info: Optional[ExtraInfo]) -> Tab raise NotImplementedError("Batch data can not (yet) be stored for tabular data") return TabularData(logger=self._log, **data) - def _parse_col_def( + def _parse_col_def( # pylint: disable = too-many-arguments,too-many-positional-arguments self, data: TabularData, table: str, @@ -394,7 +404,11 @@ def _parse_col_def( return self._parse_col_def_column_name(data=data, table=table, col_def=col_def, table_mask=table_mask) if isinstance(col_def, dict): return self._parse_col_def_filter( - data=data, table=table, table_mask=table_mask, col_def=col_def, extra_info=extra_info + data=data, + table=table, + table_mask=table_mask, + col_def=col_def, + extra_info=extra_info, ) if isinstance(col_def, list): return self._parse_col_def_composite(data=data, table=table, col_def=col_def, table_mask=table_mask) @@ -402,7 +416,10 @@ def _parse_col_def( @staticmethod def _parse_col_def_const( - data: TabularData, table: str, col_def: Union[int, float], table_mask: Optional[np.ndarray] = None + data: TabularData, + table: str, + col_def: Union[int, float], + table_mask: Optional[np.ndarray] = None, ) -> pd.DataFrame: """Create a single column pandas DataFrame containing the const value. @@ -423,7 +440,11 @@ def _parse_col_def_const( return const_df def _parse_col_def_column_name( - self, data: TabularData, table: str, col_def: str, table_mask: Optional[np.ndarray] = None + self, + data: TabularData, + table: str, + col_def: str, + table_mask: Optional[np.ndarray] = None, ) -> pd.DataFrame: """Extract a column from the data. If the column doesn't exist, check if the col_def is a special float value, like 'inf'. If that's the case, create a single column pandas DataFrame containing the const value. @@ -471,7 +492,7 @@ def _apply_multiplier(self, table: str, column: str, data: pd.Series) -> pd.Seri except KeyError: return data - def _parse_reference( + def _parse_reference( # pylint: disable = too-many-arguments,too-many-positional-arguments self, data: TabularData, table: str, @@ -502,7 +523,7 @@ def _parse_reference( result = queries.merge(other, how="left", left_on=query_column, right_on=key_column) return result[[value_column]] - def _parse_col_def_filter( + def _parse_col_def_filter( # pylint: disable = too-many-arguments,too-many-positional-arguments self, data: TabularData, table: str, @@ -553,18 +574,26 @@ def _parse_col_def_filter( ) elif isinstance(sub_def, list): col_data = self._parse_pandas_function( - data=data, table=table, table_mask=table_mask, fn_name=name, col_def=sub_def + data=data, + table=table, + table_mask=table_mask, + fn_name=name, + col_def=sub_def, ) elif isinstance(sub_def, dict): col_data = self._parse_function( - data=data, table=table, table_mask=table_mask, function=name, col_def=sub_def + data=data, + table=table, + table_mask=table_mask, + function=name, + col_def=sub_def, ) else: raise TypeError(f"Invalid {name} definition: {sub_def}") data_frames.append(col_data) return pd.concat(data_frames, axis=1) - def _parse_auto_id( + def _parse_auto_id( # pylint: disable = too-many-arguments,too-many-positional-arguments self, data: TabularData, table: str, @@ -606,7 +635,11 @@ def _parse_auto_id( raise TypeError(f"Invalid key definition type '{type(key_col_def).__name__}': {key_col_def}") col_data = self._parse_col_def( - data=data, table=table, table_mask=table_mask, col_def=key_col_def, extra_info=None + data=data, + table=table, + table_mask=table_mask, + col_def=key_col_def, + extra_info=None, ) def auto_id(row: np.ndarray): @@ -622,7 +655,13 @@ def auto_id(row: np.ndarray): # the first argument to be parsed. if extra_info is not None and ref_table_str == table and pgm_id not in extra_info: if ref_name is not None: - extra_info[pgm_id] = {"id_reference": {"table": ref_table_str, "name": ref_name, "key": key}} + extra_info[pgm_id] = { + "id_reference": { + "table": ref_table_str, + "name": ref_name, + "key": key, + } + } else: extra_info[pgm_id] = {"id_reference": {"table": ref_table_str, "key": key}} @@ -632,8 +671,13 @@ def auto_id(row: np.ndarray): return col_data return col_data.apply(auto_id, axis=1, raw=True) - def _parse_pandas_function( - self, data: TabularData, table: str, fn_name: str, col_def: List[Any], table_mask: Optional[np.ndarray] + def _parse_pandas_function( # pylint: disable = too-many-arguments,too-many-positional-arguments + self, + data: TabularData, + table: str, + fn_name: str, + col_def: List[Any], + table_mask: Optional[np.ndarray], ) -> pd.DataFrame: """Special vectorized functions. @@ -652,7 +696,13 @@ def _parse_pandas_function( if fn_name == "multiply": fn_name = "prod" - col_data = self._parse_col_def(data=data, table=table, col_def=col_def, table_mask=table_mask, extra_info=None) + col_data = self._parse_col_def( + data=data, + table=table, + col_def=col_def, + table_mask=table_mask, + extra_info=None, + ) try: fn_ptr = getattr(col_data, fn_name) @@ -675,8 +725,13 @@ def _parse_pandas_function( return pd.DataFrame(fn_ptr(axis=1)) - def _parse_function( - self, data: TabularData, table: str, function: str, col_def: Dict[str, Any], table_mask: Optional[np.ndarray] + def _parse_function( # pylint: disable = too-many-arguments,too-many-positional-arguments + self, + data: TabularData, + table: str, + function: str, + col_def: Dict[str, Any], + table_mask: Optional[np.ndarray], ) -> pd.DataFrame: """Import the function by name and apply it to each row. @@ -694,7 +749,13 @@ def _parse_function( fn_ptr = get_function(function) key_words = list(col_def.keys()) sub_def = list(col_def.values()) - col_data = self._parse_col_def(data=data, table=table, col_def=sub_def, table_mask=table_mask, extra_info=None) + col_data = self._parse_col_def( + data=data, + table=table, + col_def=sub_def, + table_mask=table_mask, + extra_info=None, + ) if col_data.empty: raise ValueError(f"Cannot apply function {function} to an empty DataFrame") @@ -703,7 +764,11 @@ def _parse_function( return pd.DataFrame(col_data) def _parse_col_def_composite( - self, data: TabularData, table: str, col_def: list, table_mask: Optional[np.ndarray] + self, + data: TabularData, + table: str, + col_def: list, + table_mask: Optional[np.ndarray], ) -> pd.DataFrame: """Select multiple columns (each is created from a column definition) and return them as a new DataFrame. @@ -717,7 +782,13 @@ def _parse_col_def_composite( """ assert isinstance(col_def, list) columns = [ - self._parse_col_def(data=data, table=table, col_def=sub_def, table_mask=table_mask, extra_info=None) + self._parse_col_def( + data=data, + table=table, + col_def=sub_def, + table_mask=table_mask, + extra_info=None, + ) for sub_def in col_def ] return pd.concat(columns, axis=1) @@ -748,7 +819,12 @@ def get_id(self, table: str, key: Mapping[str, int], name: Optional[str] = None) raise KeyError((table, key, name)) return self._auto_id(item=(table, key, name), key=auto_id_key) - def get_ids(self, keys: pd.DataFrame, table: Optional[str] = None, name: Optional[str] = None) -> List[int]: + def get_ids( + self, + keys: pd.DataFrame, + table: Optional[str] = None, + name: Optional[str] = None, + ) -> List[int]: """ Get a the numerical ID previously associated with the supplied name / key combination Args: diff --git a/src/power_grid_model_io/converters/vision_excel_converter.py b/src/power_grid_model_io/converters/vision_excel_converter.py index 36ca1a62..a9f88658 100644 --- a/src/power_grid_model_io/converters/vision_excel_converter.py +++ b/src/power_grid_model_io/converters/vision_excel_converter.py @@ -35,14 +35,14 @@ class VisionExcelConverter(TabularConverter): Vision Excel Converter: Load data from a Vision Excel export file and use a mapping file to convert the data to PGM """ - def __init__( + def __init__( # pylint: disable=too-many-arguments,too-many-positional-arguments self, source_file: Optional[Union[Path, str]] = None, language: str = LANGUAGE_EN, terms_changed: Optional[dict] = None, mapping_file: Optional[Union[Path, str]] = None, log_level: int = logging.INFO, - ): # pylint: disable=too-many-arguments + ): _mapping_file = Path( mapping_file if mapping_file is not None else str(DEFAULT_MAPPING_FILE).format(language=language) ) diff --git a/src/power_grid_model_io/functions/phase_to_phase.py b/src/power_grid_model_io/functions/phase_to_phase.py index 02110331..f46da0a9 100644 --- a/src/power_grid_model_io/functions/phase_to_phase.py +++ b/src/power_grid_model_io/functions/phase_to_phase.py @@ -33,7 +33,7 @@ def reactive_power(p: float, cos_phi: float) -> float: return p * math.sqrt(1 - cos_phi**2) / cos_phi -def power_wind_speed( # pylint: disable=too-many-arguments +def power_wind_speed( # pylint: disable=too-many-arguments,too-many-positional-arguments p_nom: float, wind_speed: float, cut_in_wind_speed: float = 3.0, From b5d161ef71836ed42c30b6501673dd90a9600a9b Mon Sep 17 00:00:00 2001 From: Martijn Govers Date: Mon, 30 Sep 2024 11:02:13 +0200 Subject: [PATCH 2/2] pylint + pytest Signed-off-by: Martijn Govers --- .../converters/pandapower_converter.py | 122 ++++++++++++++---- 1 file changed, 98 insertions(+), 24 deletions(-) diff --git a/src/power_grid_model_io/converters/pandapower_converter.py b/src/power_grid_model_io/converters/pandapower_converter.py index 847bce87..d867ef09 100644 --- a/src/power_grid_model_io/converters/pandapower_converter.py +++ b/src/power_grid_model_io/converters/pandapower_converter.py @@ -5,6 +5,7 @@ """ Panda Power Converter """ + import logging from functools import lru_cache from typing import Dict, List, MutableMapping, Optional, Tuple, Type, Union @@ -39,9 +40,21 @@ class PandaPowerConverter(BaseConverter[PandaPowerData]): Panda Power Converter """ - __slots__ = ("pp_input_data", "pgm_input_data", "idx", "idx_lookup", "next_idx", "system_frequency") + __slots__ = ( + "pp_input_data", + "pgm_input_data", + "idx", + "idx_lookup", + "next_idx", + "system_frequency", + ) - def __init__(self, system_frequency: float = 50.0, trafo_loading: str = "current", log_level: int = logging.INFO): + def __init__( + self, + system_frequency: float = 50.0, + trafo_loading: str = "current", + log_level: int = logging.INFO, + ): """ Prepare some member variables @@ -60,7 +73,12 @@ def __init__(self, system_frequency: float = 50.0, trafo_loading: str = "current self.idx_lookup: Dict[Tuple[str, Optional[str]], pd.Series] = {} self.next_idx = 0 - def _parse_data(self, data: PandaPowerData, data_type: str, extra_info: Optional[ExtraInfo] = None) -> Dataset: + def _parse_data( + self, + data: PandaPowerData, + data_type: str, + extra_info: Optional[ExtraInfo] = None, + ) -> Dataset: """ Set up for conversion from PandaPower to power-grid-model @@ -172,7 +190,13 @@ def _fill_pgm_extra_info(self, extra_info: ExtraInfo): for (pp_table, name), indices in self.idx_lookup.items(): for pgm_id, pp_idx in zip(indices.index, indices): if name: - extra_info[pgm_id] = {"id_reference": {"table": pp_table, "name": name, "index": pp_idx}} + extra_info[pgm_id] = { + "id_reference": { + "table": pp_table, + "name": name, + "index": pp_idx, + } + } else: extra_info[pgm_id] = {"id_reference": {"table": pp_table, "index": pp_idx}} @@ -850,8 +874,8 @@ def _create_pgm_input_three_winding_transformers(self): # Default vector group for odd clocks_12 = Yndx, for odd clocks_13 = Ynxd and for even clocks = YNxyn or YNynx no_vector_groups = ( np.isnan(winding_types["winding_1"]) - | np.isnan(winding_types["winding_2"]) - | np.isnan(winding_types["winding_3"]) + & np.isnan(winding_types["winding_2"]) + & np.isnan(winding_types["winding_3"]) ) no_vector_groups_ynd2 = no_vector_groups & (clocks_12 % 2) no_vector_groups_ynd3 = no_vector_groups & (clocks_13 % 2) @@ -860,7 +884,9 @@ def _create_pgm_input_three_winding_transformers(self): winding_types.loc[no_vector_groups_ynd3, "winding_3"] = WindingType.delta pgm_3wtransformers = initialize_array( - data_type="input", component_type="three_winding_transformer", shape=len(pp_trafo3w) + data_type="input", + component_type="three_winding_transformer", + shape=len(pp_trafo3w), ) pgm_3wtransformers["id"] = self._generate_ids("trafo3w", pp_trafo3w.index) @@ -995,7 +1021,8 @@ def _create_pgm_input_wards(self): if "sym_load" in self.pgm_input_data: symload_dtype = self.pgm_input_data["sym_load"].dtype self.pgm_input_data["sym_load"] = np.concatenate( # pylint: disable=unexpected-keyword-arg - [self.pgm_input_data["sym_load"], pgm_sym_loads_from_ward], dtype=symload_dtype + [self.pgm_input_data["sym_load"], pgm_sym_loads_from_ward], + dtype=symload_dtype, ) else: self.pgm_input_data["sym_load"] = pgm_sym_loads_from_ward @@ -1036,7 +1063,10 @@ def _create_pgm_input_motors(self): p_spec = pgm_sym_loads_from_motor["p_specified"] cos_phi = self._get_pp_attr("motor", "cos_phi", expected_type="f8") valid = np.logical_and(np.not_equal(cos_phi, 0.0), np.isfinite(cos_phi)) - q_spec = np.sqrt(np.power(np.divide(p_spec, cos_phi, where=valid), 2, where=valid) - p_spec**2, where=valid) + q_spec = np.sqrt( + np.power(np.divide(p_spec, cos_phi, where=valid), 2, where=valid) - p_spec**2, + where=valid, + ) q_spec[np.logical_not(valid)] = np.nan pgm_sym_loads_from_motor["q_specified"] = q_spec @@ -1045,7 +1075,8 @@ def _create_pgm_input_motors(self): if "sym_load" in self.pgm_input_data: symload_dtype = self.pgm_input_data["sym_load"].dtype self.pgm_input_data["sym_load"] = np.concatenate( # pylint: disable=unexpected-keyword-arg - [self.pgm_input_data["sym_load"], pgm_sym_loads_from_motor], dtype=symload_dtype + [self.pgm_input_data["sym_load"], pgm_sym_loads_from_motor], + dtype=symload_dtype, ) else: self.pgm_input_data["sym_load"] = pgm_sym_loads_from_motor @@ -1112,8 +1143,15 @@ def _pp_buses_output__accumulate_power(self, pp_output_buses: pd.DataFrame): component_sides = { "line": [("from_node", "p_from", "q_from"), ("to_node", "p_to", "q_to")], "link": [("from_node", "p_from", "q_from"), ("to_node", "p_to", "q_to")], - "transformer": [("from_node", "p_from", "q_from"), ("to_node", "p_to", "q_to")], - "three_winding_transformer": [("node_1", "p_1", "q_1"), ("node_2", "p_2", "q_2"), ("node_3", "p_3", "q_3")], + "transformer": [ + ("from_node", "p_from", "q_from"), + ("to_node", "p_to", "q_to"), + ], + "three_winding_transformer": [ + ("node_1", "p_1", "q_1"), + ("node_2", "p_2", "q_2"), + ("node_3", "p_3", "q_3"), + ], } # Set the initial powers to zero @@ -1229,7 +1267,8 @@ def _pp_ext_grids_output(self): pgm_output_sources = self.pgm_output_data["source"] pp_output_ext_grids = pd.DataFrame( - columns=["p_mw", "q_mvar"], index=self._get_pp_ids("ext_grid", pgm_output_sources["id"]) + columns=["p_mw", "q_mvar"], + index=self._get_pp_ids("ext_grid", pgm_output_sources["id"]), ) pp_output_ext_grids["p_mw"] = pgm_output_sources["p"] * 1e-6 pp_output_ext_grids["q_mvar"] = pgm_output_sources["q"] * 1e-6 @@ -1256,7 +1295,8 @@ def _pp_shunts_output(self): at_nodes = self.pgm_nodes_lookup.loc[pgm_input_shunts["node"]] pp_output_shunts = pd.DataFrame( - columns=["p_mw", "q_mvar", "vm_pu"], index=self._get_pp_ids("shunt", pgm_output_shunts["id"]) + columns=["p_mw", "q_mvar", "vm_pu"], + index=self._get_pp_ids("shunt", pgm_output_shunts["id"]), ) pp_output_shunts["p_mw"] = pgm_output_shunts["p"] * 1e-6 pp_output_shunts["q_mvar"] = pgm_output_shunts["q"] * 1e-6 @@ -1280,7 +1320,8 @@ def _pp_sgens_output(self): pgm_output_sym_gens = self.pgm_output_data["sym_gen"] pp_output_sgens = pd.DataFrame( - columns=["p_mw", "q_mvar"], index=self._get_pp_ids("sgen", pgm_output_sym_gens["id"]) + columns=["p_mw", "q_mvar"], + index=self._get_pp_ids("sgen", pgm_output_sym_gens["id"]), ) pp_output_sgens["p_mw"] = pgm_output_sym_gens["p"] * 1e-6 pp_output_sgens["q_mvar"] = pgm_output_sym_gens["q"] * 1e-6 @@ -1707,12 +1748,22 @@ def _pp_buses_output_3ph__accumulate_power(self, pp_output_buses_3ph: pd.DataFra Returns: accumulated power for each bus """ - power_columns = ["p_a_mw", "p_b_mw", "p_c_mw", "q_a_mvar", "q_b_mvar", "q_c_mvar"] + power_columns = [ + "p_a_mw", + "p_b_mw", + "p_c_mw", + "q_a_mvar", + "q_b_mvar", + "q_c_mvar", + ] # Let's define all the components and sides where nodes can be connected component_sides = { "line": [("from_node", "p_from", "q_from"), ("to_node", "p_to", "q_to")], "link": [("from_node", "p_from", "q_from"), ("to_node", "p_to", "q_to")], - "transformer": [("from_node", "p_from", "q_from"), ("to_node", "p_to", "q_to")], + "transformer": [ + ("from_node", "p_from", "q_from"), + ("to_node", "p_to", "q_to"), + ], } # Set the initial powers to zero @@ -1902,7 +1953,8 @@ def _pp_sgens_output_3ph(self): pgm_output_sym_gens = self.pgm_output_data["sym_gen"] pp_output_sgens = pd.DataFrame( - columns=["p_mw", "q_mvar"], index=self._get_pp_ids("sgen", pgm_output_sym_gens["id"]) + columns=["p_mw", "q_mvar"], + index=self._get_pp_ids("sgen", pgm_output_sym_gens["id"]), ) pp_output_sgens["p_mw"] = np.sum(pgm_output_sym_gens["p"], axis=1) * 1e-6 pp_output_sgens["q_mvar"] = np.sum(pgm_output_sym_gens["q"], axis=1) * 1e-6 @@ -1938,15 +1990,24 @@ def _pp_trafos_output_3ph(self): # pylint: disable=too-many-statements loading = np.maximum(np.sum(ui_from, axis=1), np.sum(ui_to, axis=1)) / pgm_input_transformers["sn"] elif self.trafo_loading == "power": loading_a_percent = ( - np.maximum(pgm_output_transformers["s_from"][:, 0], pgm_output_transformers["s_to"][:, 0]) + np.maximum( + pgm_output_transformers["s_from"][:, 0], + pgm_output_transformers["s_to"][:, 0], + ) / pgm_output_transformers["s_n"] ) loading_b_percent = ( - np.maximum(pgm_output_transformers["s_from"][:, 1], pgm_output_transformers["s_to"][:, 1]) + np.maximum( + pgm_output_transformers["s_from"][:, 1], + pgm_output_transformers["s_to"][:, 1], + ) / pgm_output_transformers["s_n"] ) loading_c_percent = ( - np.maximum(pgm_output_transformers["s_from"][:, 2], pgm_output_transformers["s_to"][:, 2]) + np.maximum( + pgm_output_transformers["s_from"][:, 2], + pgm_output_transformers["s_to"][:, 2], + ) / pgm_output_transformers["s_n"] ) loading = pgm_output_transformers["loading"] @@ -2136,7 +2197,10 @@ def _generate_ids(self, pp_table: str, pp_idx: pd.Index, name: Optional[str] = N return pgm_idx def _get_pgm_ids( - self, pp_table: str, pp_idx: Optional[Union[pd.Series, np.ndarray]] = None, name: Optional[str] = None + self, + pp_table: str, + pp_idx: Optional[Union[pd.Series, np.ndarray]] = None, + name: Optional[str] = None, ) -> pd.Series: """ Get numerical power-grid-model IDs for a PandaPower component @@ -2155,7 +2219,12 @@ def _get_pgm_ids( return self.idx[key] return self.idx[key][pp_idx] - def _get_pp_ids(self, pp_table: str, pgm_idx: Optional[pd.Series] = None, name: Optional[str] = None) -> pd.Series: + def _get_pp_ids( + self, + pp_table: str, + pgm_idx: Optional[pd.Series] = None, + name: Optional[str] = None, + ) -> pd.Series: """ Get numerical PandaPower IDs for a PandaPower component @@ -2348,7 +2417,12 @@ def get_trafo3w_switch_states(self, trafo3w: pd.DataFrame) -> pd.DataFrame: pp_3_switches = self.get_individual_switch_states(trafo3w[["index", bus3]], pp_switches, bus3) return pd.DataFrame( - data={"side_1": pp_1_switches, "side_2": pp_2_switches, "side_3": pp_3_switches}, index=trafo3w.index + data={ + "side_1": pp_1_switches, + "side_2": pp_2_switches, + "side_3": pp_3_switches, + }, + index=trafo3w.index, ) def get_trafo_winding_types(self) -> pd.DataFrame: