Skip to content

Commit

Permalink
Fix pytest and pylint warnings (#884)
Browse files Browse the repository at this point in the history
Signed-off-by: Damien Jeandemange <[email protected]>
  • Loading branch information
jeandemanged authored Nov 20, 2024
1 parent e1080db commit 9c6a0fa
Show file tree
Hide file tree
Showing 17 changed files with 504 additions and 463 deletions.
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -582,5 +582,5 @@ preferred-modules=

# Exceptions that will emit a warning when being caught. Defaults to
# "BaseException, Exception".
overgeneral-exceptions=BaseException,
Exception
overgeneral-exceptions=builtins.BaseException,
builtins.Exception
2 changes: 1 addition & 1 deletion pypowsybl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
]


# setup a default logger that is the powsybl logger with by default no handler to avoir printing logs >= WARNING
# setup a default logger that is the powsybl logger with by default no handler to avoid printing logs >= WARNING
# to std err
powsyblLogger = logging.getLogger('powsybl')
powsyblLogger.addHandler(logging.NullHandler())
Expand Down
215 changes: 108 additions & 107 deletions pypowsybl/_pypowsybl.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from logging import Logger
from typing import ClassVar, Dict, Iterator, List, Sequence, Optional, Union
from numpy.typing import ArrayLike as _ArrayLike
from logging import Logger

class ArrayStruct:
def __init__(self) -> None: ...
Expand Down Expand Up @@ -102,6 +102,89 @@ class SensitivityVariableType:
@property
def name(self) -> str: ...

class LimitType:
__members__: ClassVar[Dict[str, LimitType]] = ... # read-only
ACTIVE_POWER: ClassVar[LimitType] = ...
APPARENT_POWER: ClassVar[LimitType] = ...
CURRENT: ClassVar[LimitType] = ...
LOW_VOLTAGE: ClassVar[LimitType] = ...
HIGH_VOLTAGE: ClassVar[LimitType] = ...
LOW_VOLTAGE_ANGLE: ClassVar[LimitType] = ...
HIGH_VOLTAGE_ANGLE: ClassVar[LimitType] = ...
LOW_SHORT_CIRCUIT_CURRENT: ClassVar[LimitType] = ...
HIGH_SHORT_CIRCUIT_CURRENT: ClassVar[LimitType] = ...
OTHER: ClassVar[LimitType] = ...
def __init__(self, arg0: int) -> None: ...
def __eq__(self, arg0: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, arg0: object) -> bool: ...
def __setstate__(self, arg0: int) -> None: ...
@property
def name(self) -> str: ...

class Side:
__members__: ClassVar[Dict[str, Side]] = ... # read-only
NONE: ClassVar[Side] = ...
ONE: ClassVar[Side] = ...
TWO: ClassVar[Side] = ...
THREE: ClassVar[Side] = ...
def __init__(self, arg0: int) -> None: ...
def __eq__(self, arg0: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, arg0: object) -> bool: ...
def __setstate__(self, arg0: int) -> None: ...
@property
def name(self) -> str: ...

class LimitViolation:
@property
def acceptable_duration(self) -> int: ...
@property
def limit(self) -> float: ...
@property
def limit_name(self) -> str: ...
@property
def limit_reduction(self) -> float: ...
@property
def limit_type(self) -> LimitType: ...
@property
def side(self) -> Side: ...
@property
def subject_id(self) -> str: ...
@property
def subject_name(self) -> str: ...
@property
def value(self) -> float: ...

class LimitViolationArray:
def __iter__(self) -> Iterator: ...
def __len__(self) -> int: ...
def __getitem__(self) -> LimitViolation: ...

class PostContingencyComputationStatus:
__members__: ClassVar[Dict[str, PostContingencyComputationStatus]] = ... # read-only
CONVERGED: ClassVar[PostContingencyComputationStatus] = ...
FAILED: ClassVar[PostContingencyComputationStatus] = ...
MAX_ITERATION_REACHED: ClassVar[PostContingencyComputationStatus] = ...
SOLVER_FAILED: ClassVar[PostContingencyComputationStatus] = ...
NO_IMPACT: ClassVar[PostContingencyComputationStatus] = ...
def __init__(self, arg0: int) -> None: ...
def __eq__(self, arg0: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, arg0: object) -> bool: ...
def __setstate__(self, arg0: int) -> None: ...
@property
def name(self) -> str: ...

class PostContingencyResult:
@property
def contingency_id(self) -> str: ...
Expand All @@ -118,6 +201,23 @@ class OperatorStrategyResult:
@property
def status(self) -> PostContingencyComputationStatus: ...

class LoadFlowComponentStatus:
__members__: ClassVar[Dict[str, LoadFlowComponentStatus]] = ... # read-only
CONVERGED: ClassVar[LoadFlowComponentStatus] = ...
FAILED: ClassVar[LoadFlowComponentStatus] = ...
MAX_ITERATION_REACHED: ClassVar[LoadFlowComponentStatus] = ...
NO_CALCULATION: ClassVar[LoadFlowComponentStatus] = ...
def __init__(self, arg0: int) -> None: ...
def __eq__(self, arg0: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, arg0: object) -> bool: ...
def __setstate__(self, arg0: int) -> None: ...
@property
def name(self) -> str: ...

class PreContingencyResult:
@property
def limit_violations(self) -> LimitViolationArray: ...
Expand Down Expand Up @@ -308,54 +408,6 @@ class NadParameters:
edge_info_displayed: EdgeInfoType
def __init__(self) -> None: ...

class LimitType:
__members__: ClassVar[Dict[str, LimitType]] = ... # read-only
ACTIVE_POWER: ClassVar[LimitType] = ...
APPARENT_POWER: ClassVar[LimitType] = ...
CURRENT: ClassVar[LimitType] = ...
LOW_VOLTAGE: ClassVar[LimitType] = ...
HIGH_VOLTAGE: ClassVar[LimitType] = ...
LOW_VOLTAGE_ANGLE: ClassVar[LimitType] = ...
HIGH_VOLTAGE_ANGLE: ClassVar[LimitType] = ...
LOW_SHORT_CIRCUIT_CURRENT: ClassVar[LimitType] = ...
HIGH_SHORT_CIRCUIT_CURRENT: ClassVar[LimitType] = ...
OTHER: ClassVar[LimitType] = ...
def __init__(self, arg0: int) -> None: ...
def __eq__(self, arg0: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, arg0: object) -> bool: ...
def __setstate__(self, arg0: int) -> None: ...
@property
def name(self) -> str: ...

class LimitViolation:
@property
def acceptable_duration(self) -> int: ...
@property
def limit(self) -> float: ...
@property
def limit_name(self) -> str: ...
@property
def limit_reduction(self) -> float: ...
@property
def limit_type(self) -> LimitType: ...
@property
def side(self) -> Side: ...
@property
def subject_id(self) -> str: ...
@property
def subject_name(self) -> str: ...
@property
def value(self) -> float: ...

class LimitViolationArray:
def __iter__(self) -> Iterator: ...
def __len__(self) -> int: ...
def __getitem__(self) -> LimitViolation: ...

class SlackBusResult:
@property
def id(self) -> str: ...
Expand Down Expand Up @@ -390,30 +442,11 @@ class LoadFlowComponentResultArray:
def __len__(self) -> int: ...
def __getitem__(self) -> LoadFlowComponentResult: ...

class LoadFlowComponentStatus:
__members__: ClassVar[Dict[str, LoadFlowComponentStatus]] = ... # read-only
CONVERGED: ClassVar[LoadFlowComponentStatus] = ...
FAILED: ClassVar[LoadFlowComponentStatus] = ...
MAX_ITERATION_REACHED: ClassVar[LoadFlowComponentStatus] = ...
NO_CALCULATION: ClassVar[LoadFlowComponentStatus] = ...
def __init__(self, arg0: int) -> None: ...
def __eq__(self, arg0: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, arg0: object) -> bool: ...
def __setstate__(self, arg0: int) -> None: ...
@property
def name(self) -> str: ...

class PostContingencyComputationStatus:
__members__: ClassVar[Dict[str, PostContingencyComputationStatus]] = ... # read-only
CONVERGED: ClassVar[PostContingencyComputationStatus] = ...
FAILED: ClassVar[PostContingencyComputationStatus] = ...
MAX_ITERATION_REACHED: ClassVar[PostContingencyComputationStatus] = ...
SOLVER_FAILED: ClassVar[PostContingencyComputationStatus] = ...
NO_IMPACT: ClassVar[PostContingencyComputationStatus] = ...
class VoltageInitMode:
__members__: ClassVar[Dict[str, VoltageInitMode]] = ... # read-only
DC_VALUES: ClassVar[VoltageInitMode] = ...
PREVIOUS_VALUES: ClassVar[VoltageInitMode] = ...
UNIFORM_VALUES: ClassVar[VoltageInitMode] = ...
def __init__(self, arg0: int) -> None: ...
def __eq__(self, arg0: object) -> bool: ...
def __getstate__(self) -> int: ...
Expand Down Expand Up @@ -490,7 +523,8 @@ class NetworkMetadata:
@property
def source_format(self) -> str: ...

class PyPowsyblError(Exception): ...
class PyPowsyblError(Exception):
...

class Series:
@property
Expand Down Expand Up @@ -518,23 +552,6 @@ class SeriesMetadata:
@property
def type(self) -> int: ...

class Side:
__members__: ClassVar[Dict[str, Side]] = ... # read-only
NONE: ClassVar[Side] = ...
ONE: ClassVar[Side] = ...
TWO: ClassVar[Side] = ...
THREE: ClassVar[Side] = ...
def __init__(self, arg0: int) -> None: ...
def __eq__(self, arg0: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, arg0: object) -> bool: ...
def __setstate__(self, arg0: int) -> None: ...
@property
def name(self) -> str: ...

class ValidationLevel:
__members__: ClassVar[Dict[str, ValidationLevel]] = ... # read-only
EQUIPMENT: ClassVar[ValidationLevel] = ...
Expand Down Expand Up @@ -571,22 +588,6 @@ class ValidationType:
@property
def name(self) -> str: ...

class VoltageInitMode:
__members__: ClassVar[Dict[str, VoltageInitMode]] = ... # read-only
DC_VALUES: ClassVar[VoltageInitMode] = ...
PREVIOUS_VALUES: ClassVar[VoltageInitMode] = ...
UNIFORM_VALUES: ClassVar[VoltageInitMode] = ...
def __init__(self, arg0: int) -> None: ...
def __eq__(self, arg0: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, arg0: object) -> bool: ...
def __setstate__(self, arg0: int) -> None: ...
@property
def name(self) -> str: ...

class Zone:
def __init__(self, id: str, injections_ids: List[str], injections_shift_keys: List[float]) -> None: ...

Expand Down
3 changes: 1 addition & 2 deletions pypowsybl/network/impl/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3653,8 +3653,7 @@ def get_operational_limits(self, all_attributes: bool = False, attributes: List[
"""
if show_inactive_sets:
return self.get_elements(ElementType.OPERATIONAL_LIMITS, all_attributes, attributes)
else:
return self.get_elements(ElementType.SELECTED_OPERATIONAL_LIMITS, all_attributes, attributes)
return self.get_elements(ElementType.SELECTED_OPERATIONAL_LIMITS, all_attributes, attributes)

def get_node_breaker_topology(self, voltage_level_id: str) -> NodeBreakerTopology:
"""
Expand Down
3 changes: 1 addition & 2 deletions pypowsybl/network/impl/network_element_modification_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,7 @@ def create_voltage_level_topology(network: Network, df: DataFrame = None, raise_
def transform_list_to_str(entry: Union[str, List[str]]) -> str:
if isinstance(entry, list):
return ','.join(str(e.replace(' ', '')) for e in entry)
if isinstance(entry, str):
return entry.replace(' ', '')
return entry.replace(' ', '')


def create_coupling_device(network: Network, df: DataFrame = None, raise_exception: bool = True,
Expand Down
38 changes: 19 additions & 19 deletions pypowsybl/network/impl/pandapower_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

import numpy as np
import pandas as pd
import pypowsybl._pypowsybl as _pp
from pandas import Series
from pandas import DataFrame
import pypowsybl._pypowsybl as _pp
try:
from pandapower import pandapowerNet
except ImportError:
Expand All @@ -32,21 +32,21 @@
def convert_from_pandapower(n_pdp: pandapowerNet) -> Network:
if util.find_spec("pandapower") is None:
raise _pp.PyPowsyblError("pandapower is not installed")
else:
n = create_empty(n_pdp.name if n_pdp.name else 'network')

# create one giant substation
n.create_substations(id='s')
create_buses(n, n_pdp)
create_loads(n, n_pdp)
slack_weight_by_gen_id: Dict[str, float] = {}
create_generators(n, n_pdp, slack_weight_by_gen_id)
create_shunts(n, n_pdp)
create_lines(n, n_pdp)
create_transformers(n, n_pdp)
create_extensions(n, slack_weight_by_gen_id)
n = create_empty(n_pdp.name if n_pdp.name else 'network')

# create one giant substation
n.create_substations(id='s')
create_buses(n, n_pdp)
create_loads(n, n_pdp)
slack_weight_by_gen_id: Dict[str, float] = {}
create_generators(n, n_pdp, slack_weight_by_gen_id)
create_shunts(n, n_pdp)
create_lines(n, n_pdp)
create_transformers(n, n_pdp)
create_extensions(n, slack_weight_by_gen_id)

return n
return n


def create_extensions(n: Network, slack_weight_by_gen_id: Dict[str, float]) -> None:
Expand All @@ -62,7 +62,7 @@ def create_extensions(n: Network, slack_weight_by_gen_id: Dict[str, float]) -> N

# create active power control extension to define the distribution key
n.create_extensions(extension_name='activePowerControl', id=gen_id,
participate=True if abs(weight) > 0.001 else False, droop=weight)
participate=abs(weight) > 0.001, droop=weight)


def get_name(df: pd.DataFrame, name: str) -> pd.Series:
Expand All @@ -81,7 +81,7 @@ def build_bus_id(bus: Series) -> pd.Series:


def build_injection_id(prefix: str, bus: pd.Series, index: int) -> str:
return "{}_{}_{}".format(prefix, bus, index) # because it is required by grid2op to build IDs like this is case of missing name
return f'{prefix}_{bus}_{index}' # because it is required by grid2op to build IDs like this is case of missing name


def generate_injection_id(df: pd.DataFrame, prefix: str) -> pd.Series:
Expand All @@ -91,7 +91,7 @@ def generate_injection_id(df: pd.DataFrame, prefix: str) -> pd.Series:
def build_line_id(row: pd.Series, index: int) -> str:
from_bus = row['from_bus']
to_bus = row['to_bus']
return "{}_{}_{}".format(from_bus, to_bus, index) # because it is required by grid2op to build IDs like this is case of missing name
return f'{from_bus}_{to_bus}_{index}' # because it is required by grid2op to build IDs like this is case of missing name


def generate_line_id(df: pd.DataFrame) -> pd.Series:
Expand All @@ -101,7 +101,7 @@ def generate_line_id(df: pd.DataFrame) -> pd.Series:
def build_transformer_id(row: pd.Series, index: int, index_offset: int) -> str:
hv_bus = row['hv_bus']
lv_bus = row['lv_bus']
return "{}_{}_{}".format(hv_bus, lv_bus, index_offset + index) # because it is required by grid2op to build IDs like this is case of missing name
return f'{hv_bus}_{lv_bus}_{index_offset + index}' # because it is required by grid2op to build IDs like this is case of missing name


def generate_transformer_id(df: pd.DataFrame, index_offset: int) -> pd.Series:
Expand Down Expand Up @@ -255,7 +255,7 @@ def create_generator_min_p(gen_and_bus: DataFrame, generator_type: PandaPowerGen

def create_generator_target_q(gen_and_bus: DataFrame, generator_type: PandaPowerGeneratorType) -> pd.Series:
return gen_and_bus[
'q_mvar'] if generator_type == PandaPowerGeneratorType.STATIC_GENERATOR in gen_and_bus.columns else pd.Series(
'q_mvar'] if generator_type == PandaPowerGeneratorType.STATIC_GENERATOR and 'q_mvar' in gen_and_bus.columns else pd.Series(
[0.0] * len(gen_and_bus))


Expand Down
Loading

0 comments on commit 9c6a0fa

Please sign in to comment.