1
# -*- coding: utf-8 -*-
2

3
# Copyright (c) 2016-2020 by University of Kassel and Fraunhofer Institute for Energy Economics
4
# and Energy System Technology (IEE), Kassel. All rights reserved.
5

6 1
from packaging import version
7

8 1
from pandapipes import __version__
9

10 1
try:
11 1
    import pplog as logging
12 1
except ImportError:
13 1
    import logging
14

15 1
logger = logging.getLogger(__name__)
16

17

18 1
def convert_format(net):
19
    """
20
    Converts old nets to new format to ensure consistency. The converted net is returned.
21
    """
22 1
    if isinstance(net.version, str) and version.parse(net.version) >= version.parse(__version__):
23 1
        return net
24 1
    _rename_columns(net)
25 1
    _update_initial_run(net)
26 1
    net.version = __version__
27 1
    return net
28

29

30 1
def _rename_columns(net):
31 1
    if "controller" in net:
32 1
        if ("controller" in net.controller) and ("object" in net.controller):
33 1
            if net['controller'].at[0, 'object'] is None:
34 0
                net['controller'].drop('object', inplace=True, axis=1)
35
            else:
36 1
                net['controller'].drop('controller', inplace=True, axis=1)
37 1
        net["controller"].rename(columns={"controller": "object"}, inplace=True)
38

39

40 1
def _update_initial_run(net):
41 1
    if "controller" in net:
42 1
        for ctrl in net.controller.object.values:
43 1
            if hasattr(ctrl, 'initial_pipeflow'):
44 1
                logger.warning(
45
                    "initial_pipeflow is deprecated, but it is still an attribute in your controllers. "
46
                    "It will be removed in the future. Please use initial_run instead!")
47 1
                ctrl.initial_run = ctrl.initial_pipeflow

Read our documentation on viewing source code .

Loading