Skip to content

Commit

Permalink
Upgrade pylint and fix CI (#752)
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <[email protected]>
Co-authored-by: Geoffroy Jamgotchian <[email protected]>
  • Loading branch information
EtienneLt and geofjamg authored May 27, 2024
1 parent b62ee1b commit 1792ec0
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 76 deletions.
41 changes: 25 additions & 16 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,31 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
#TODO: decide on the following checks. In practice it seems often legit.
too-many-instance-attributes,
too-many-arguments,
#TODO: following checks should be enforced in the future
line-too-long,
missing-function-docstring,
missing-module-docstring,
missing-class-docstring
disable=unexpected-special-method-signature,
too-many-statements,
unsubscriptable-object,
not-an-iterable,
too-many-branches,
too-many-locals,
unused-argument,
too-few-public-methods,
undefined-variable,
raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
#TODO: decide on the following checks. In practice it seems often legit.
too-many-instance-attributes,
too-many-arguments,
#TODO: following checks should be enforced in the future
line-too-long,
missing-function-docstring,
missing-module-docstring,
missing-class-docstring

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
11 changes: 9 additions & 2 deletions docs/user_guide/per_unit.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Per Unit data
---------------

.. testsetup:: *

import pypowsybl as pp
import pandas as pd
pd.options.display.max_columns = None
pd.options.display.expand_frame_repr = False

PyPowSyBl provides methods to per unit the scientific data. They are part of the network api.
To per-unit the data, the attribute per_unit of the network has to be set.

Expand All @@ -9,7 +16,7 @@ To per-unit the data, the attribute per_unit of the network has to be set.

>>> net = pp.network.create_four_substations_node_breaker_network()
>>> net.per_unit=True
>>> net.get_lines() # doctest: +NORMALIZE_WHITESPACE
>>> net.get_lines()
name r x g1 b1 g2 b2 p1 q1 i1 p2 q2 i2 voltage_level1_id voltage_level2_id bus1_id bus2_id connected1 connected2
id
LINE_S2S3 0.000006 0.011938 0.0 0.0 0.0 0.0 1.098893 1.900229 2.147594 -1.098864 -1.845171 2.147594 S2VL1 S3VL1 S2VL1_0 S3VL1_0 True True
Expand All @@ -22,7 +29,7 @@ The nominal apparent power is by default 100 MVA. It can be set like this :
:options: +NORMALIZE_WHITESPACE

>>> net.nominal_apparent_power=250
>>> net.get_lines() # doctest: +NORMALIZE_WHITESPACE
>>> net.get_lines()
name r x g1 b1 g2 b2 p1 q1 i1 p2 q2 i2 voltage_level1_id voltage_level2_id bus1_id bus2_id connected1 connected2
id
LINE_S2S3 0.000016 0.029844 0.0 0.0 0.0 0.0 0.439557 0.760092 0.859038 -0.439546 -0.738068 0.859037 S2VL1 S3VL1 S2VL1_0 S3VL1_0 True True
Expand Down
2 changes: 1 addition & 1 deletion pypowsybl/dynamic/impl/event_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#
from typing import List
from pypowsybl import _pypowsybl as _pp
from .util import EventType
from pypowsybl._pypowsybl import Side
from .util import EventType


class EventMapping:
Expand Down
2 changes: 1 addition & 1 deletion pypowsybl/loadflow/impl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ def parameters_from_c(c_parameters: _pypowsybl.LoadFlowParameters) -> Parameters
Converts C struct to python parameters (bypassing python constructor)
"""
res = Parameters.__new__(Parameters)
res._init_from_c(c_parameters)
res._init_from_c(c_parameters) # pylint: disable=protected-access
return res
28 changes: 16 additions & 12 deletions pypowsybl/network/impl/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import pandas as pd

import pypowsybl._pypowsybl as _pp
from pypowsybl._pypowsybl import ElementType, ValidationLevel, Side
from pypowsybl._pypowsybl import ElementType, ValidationLevel
from pypowsybl.utils import (
_adapt_df_or_kwargs,
_create_c_dataframe,
Expand All @@ -45,7 +45,8 @@
from .svg import Svg
from .util import create_data_frame_from_series_array, ParamsDict

deprecated_reporter_warning = "Use of deprecated attribute reporter. Use report_node instead."
DEPRECATED_REPORTER_WARNING = "Use of deprecated attribute reporter. Use report_node instead."


class Network: # pylint: disable=too-many-public-methods

Expand Down Expand Up @@ -181,7 +182,7 @@ def save(self, file: PathOrStr, format: str = 'XIIDM', parameters: ParamsDict =
network.save('/path/to/network.uct', format='UCTE')
"""
if reporter is not None:
warnings.warn(deprecated_reporter_warning, DeprecationWarning)
warnings.warn(DEPRECATED_REPORTER_WARNING, DeprecationWarning)
report_node = reporter
file = path_to_str(file)
if parameters is None:
Expand Down Expand Up @@ -212,7 +213,7 @@ def save_to_string(self, format: str = 'XIIDM', parameters: ParamsDict = None, r
A string representing this network
"""
if reporter is not None:
warnings.warn(deprecated_reporter_warning, DeprecationWarning)
warnings.warn(DEPRECATED_REPORTER_WARNING, DeprecationWarning)
report_node = reporter

if parameters is None:
Expand All @@ -237,7 +238,7 @@ def save_to_binary_buffer(self, format: str = 'XIIDM', parameters: ParamsDict =
A BytesIO data buffer representing this network
"""
if reporter is not None:
warnings.warn(deprecated_reporter_warning, DeprecationWarning)
warnings.warn(DEPRECATED_REPORTER_WARNING, DeprecationWarning)
report_node = reporter

if parameters is None:
Expand Down Expand Up @@ -323,7 +324,7 @@ def write_network_area_diagram_svg(self, svg_file: PathOrStr, voltage_level_ids:
Create a network area diagram in SVG format and write it to a file.
Args:
svg_file: a svg file path
voltage_level_id: the voltage level ID, center of the diagram (None for the full diagram)
voltage_level_ids: the voltage level ID, center of the diagram (None for the full diagram)
depth: the diagram depth around the voltage level
high_nominal_voltage_bound: high bound to filter voltage level according to nominal voltage
low_nominal_voltage_bound: low bound to filter voltage level according to nominal voltage
Expand All @@ -342,7 +343,7 @@ def write_network_area_diagram(self, svg_file: PathOrStr, voltage_level_ids: Uni
Args:
svg_file: a svg file path
voltage_level_id: the voltage level ID, center of the diagram (None for the full diagram)
voltage_level_ids: the voltage level ID, center of the diagram (None for the full diagram)
depth: the diagram depth around the voltage level
high_nominal_voltage_bound: high bound to filter voltage level according to nominal voltage
low_nominal_voltage_bound: low bound to filter voltage level according to nominal voltage
Expand All @@ -353,7 +354,7 @@ def write_network_area_diagram(self, svg_file: PathOrStr, voltage_level_ids: Uni
voltage_level_ids = []
if isinstance(voltage_level_ids, str):
voltage_level_ids = [voltage_level_ids]
nad_p = nad_parameters._to_c_parameters() if nad_parameters is not None else _pp.NadParameters()
nad_p = nad_parameters._to_c_parameters() if nad_parameters is not None else _pp.NadParameters() # pylint: disable=protected-access
_pp.write_network_area_diagram_svg(self._handle, svg_file, voltage_level_ids, depth, high_nominal_voltage_bound,
low_nominal_voltage_bound, nad_p)

Expand All @@ -377,7 +378,7 @@ def get_network_area_diagram(self, voltage_level_ids: Union[str, List[str]] = No
voltage_level_ids = []
if isinstance(voltage_level_ids, str):
voltage_level_ids = [voltage_level_ids]
nad_p = nad_parameters._to_c_parameters() if nad_parameters is not None else _pp.NadParameters()
nad_p = nad_parameters._to_c_parameters() if nad_parameters is not None else _pp.NadParameters() # pylint: disable=protected-access
return Svg(_pp.get_network_area_diagram_svg(self._handle, voltage_level_ids, depth,
high_nominal_voltage_bound, low_nominal_voltage_bound,
nad_p))
Expand Down Expand Up @@ -409,7 +410,8 @@ def get_elements_ids(self, element_type: ElementType, nominal_voltages: Set[floa
main_connected_component, main_synchronous_component,
not_connected_to_same_bus_at_both_sides)

def get_elements(self, element_type: ElementType, all_attributes: bool = False, attributes: List[str] = None, **kwargs: ArrayLike) -> DataFrame:
def get_elements(self, element_type: ElementType, all_attributes: bool = False, attributes: List[str] = None,
**kwargs: ArrayLike) -> DataFrame:
"""
Get network elements as a :class:`~pandas.DataFrame` for a specified element type.
Expand Down Expand Up @@ -795,7 +797,8 @@ def get_loads(self, all_attributes: bool = False, attributes: List[str] = None,
"""
return self.get_elements(ElementType.LOAD, all_attributes, attributes, **kwargs)

def get_batteries(self, all_attributes: bool = False, attributes: List[str] = None, **kwargs: ArrayLike) -> DataFrame:
def get_batteries(self, all_attributes: bool = False, attributes: List[str] = None,
**kwargs: ArrayLike) -> DataFrame:
r"""
Get a dataframe of batteries.
Expand Down Expand Up @@ -2358,7 +2361,8 @@ def _update_elements(self, element_type: ElementType, df: DataFrame = None, **kw
metadata = _pp.get_network_elements_dataframe_metadata(element_type)
df = _adapt_df_or_kwargs(metadata, df, **kwargs)
c_df = _create_c_dataframe(df, metadata)
_pp.update_network_elements_with_series(self._handle, c_df, element_type, self._per_unit, self._nominal_apparent_power)
_pp.update_network_elements_with_series(self._handle, c_df, element_type, self._per_unit,
self._nominal_apparent_power)

def update_buses(self, df: DataFrame = None, **kwargs: ArrayLike) -> None:
"""
Expand Down
15 changes: 8 additions & 7 deletions pypowsybl/network/impl/network_creation_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from pypowsybl.utils import path_to_str
from .network import Network

deprecated_reporter_warning = "Use of deprecated attribute reporter. Use report_node instead."
DEPRECATED_REPORTER_WARNING = "Use of deprecated attribute reporter. Use report_node instead."


def _create_network(name: str, network_id: str = '') -> Network:
return Network(_pp.create_network(name, network_id))
Expand Down Expand Up @@ -194,7 +195,7 @@ def load(file: Union[str, PathLike], parameters: Dict[str, str] = None, reporter
...
"""
if reporter is not None:
warnings.warn(deprecated_reporter_warning, DeprecationWarning)
warnings.warn(DEPRECATED_REPORTER_WARNING, DeprecationWarning)
report_node = reporter
file = path_to_str(file)
if parameters is None:
Expand All @@ -218,7 +219,7 @@ def load_from_binary_buffer(buffer: io.BytesIO, parameters: Dict[str, str] = Non
The loaded network
"""
if reporter is not None:
warnings.warn(deprecated_reporter_warning, DeprecationWarning)
warnings.warn(DEPRECATED_REPORTER_WARNING, DeprecationWarning)
report_node = reporter
return load_from_binary_buffers([buffer], parameters, report_node)

Expand All @@ -238,13 +239,13 @@ def load_from_binary_buffers(buffers: List[io.BytesIO], parameters: Dict[str, st
The loaded network
"""
if reporter is not None:
warnings.warn(deprecated_reporter_warning, DeprecationWarning)
warnings.warn(DEPRECATED_REPORTER_WARNING, DeprecationWarning)
report_node = reporter
if parameters is None:
parameters = {}
buffer_list = []
for b in buffers:
buffer_list.append(b.getbuffer())
for buff in buffers:
buffer_list.append(buff.getbuffer())
return Network(_pp.load_network_from_binary_buffers(buffer_list, parameters,
None if report_node is None else report_node._report_node)) # pylint: disable=protected-access

Expand All @@ -265,7 +266,7 @@ def load_from_string(file_name: str, file_content: str, parameters: Dict[str, st
The loaded network
"""
if reporter is not None:
warnings.warn(deprecated_reporter_warning, DeprecationWarning)
warnings.warn(DEPRECATED_REPORTER_WARNING, DeprecationWarning)
report_node = reporter
if parameters is None:
parameters = {}
Expand Down
Loading

0 comments on commit 1792ec0

Please sign in to comment.