Skip to content

Commit

Permalink
fixes import bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ascheidl committed Mar 29, 2020
1 parent ee103d3 commit ccb1136
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
3 changes: 1 addition & 2 deletions pandapower/convert_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@

import pandas as pd
import numpy as np
import copy
from packaging import version
from pandapower.create import create_empty_network, create_poly_cost
from pandapower.results import reset_results
from pandapower import __version__
from pandapower.toolbox import set_data_type_of_columns_to_default


def convert_format(net):
"""
Converts old nets to new format to ensure consistency. The converted net is returned.
"""
from pandapower.toolbox import set_data_type_of_columns_to_default
if isinstance(net.version, str) and version.parse(net.version) >= version.parse(__version__):
return net
_add_nominal_power(net)
Expand Down
5 changes: 1 addition & 4 deletions pandapower/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# and Energy System Technology (IEE), Kassel. All rights reserved.




import copy
import pandas as pd
import numpy as np
Expand All @@ -18,7 +16,6 @@

logger = logging.getLogger(__name__)

import pandapower.topology as top
from pandapower.run import runpp
from pandapower.diagnostic_reports import diagnostic_report
from pandapower.toolbox import get_connected_elements
Expand Down Expand Up @@ -714,7 +711,7 @@ def disconnected_elements(net):
'disconnected sgens' : sgen_indices}
"""

import pandapower.topology as top
mg = top.create_nxgraph(net)
sections = top.connected_components(mg)
disc_elements = []
Expand Down
12 changes: 6 additions & 6 deletions pandapower/diagnostic_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import logging

logger = logging.getLogger(__name__)
from pandapower.toolbox import get_connected_buses_at_element

# separator between log messages
log_message_sep = ("\n --------\n")
Expand Down Expand Up @@ -92,6 +91,7 @@ def report_disconnected_elements(self):
logger.info("PASSED: No problematic switches found")

def report_different_voltage_levels_connected(self):
from pandapower.toolbox import get_connected_buses_at_element

if "different_voltage_levels_connected" in self.diag_results:

Expand Down Expand Up @@ -440,12 +440,12 @@ def report_multiple_voltage_controlling_elements_per_bus(self):

else:
for bus in diag_result[feeder_type]:
if feeder_type is "buses_with_mult_ext_grids":
if feeder_type == "buses_with_mult_ext_grids":
logger.warning("External grids %s are connected to bus %s. Only one "
"external grid per bus is allowed."
% (list(self.net.ext_grid[self.net.ext_grid.bus
== bus].index), bus))
elif feeder_type is "buses_with_gens_and_ext_grids":
elif feeder_type == "buses_with_gens_and_ext_grids":
logger.warning("Generator(s) %s and external grid(s) %s are connected "
"to bus %s. Only one generator OR one external grid "
"per bus is allowed."
Expand Down Expand Up @@ -480,7 +480,7 @@ def report_wrong_reference_system(self):
# message body
diag_result = self.diag_results["wrong_reference_system"]
for element_type in diag_result:
if element_type is "loads":
if element_type == "loads":
if self.compact_report:
logger.warning("loads %s: wrong reference system."
% (diag_result[element_type]))
Expand All @@ -491,7 +491,7 @@ def report_wrong_reference_system(self):
% (load, self.net.load.name.at[load],
self.net.load.p_mw.at[load]))

elif element_type is "gens":
elif element_type == "gens":
if self.compact_report:
logger.warning("gens %s: wrong reference system."
% (diag_result[element_type]))
Expand All @@ -501,7 +501,7 @@ def report_wrong_reference_system(self):
"system p_mw should be negative."
% (gen, self.net.gen.name.at[gen], self.net.gen.p_mw.at[gen]))

elif element_type is "sgens":
elif element_type == "sgens":
if self.compact_report:
logger.warning("sgens %s: wrong reference system."
% (diag_result[element_type]))
Expand Down
20 changes: 10 additions & 10 deletions pandapower/test/api/test_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import pytest

import pandapower as pp
import control
import networks
import topology
import pandapower.control
import pandapower.networks
import pandapower.topology
from pandapower.io_utils import PPJSONEncoder, PPJSONDecoder
from pandapower.test.toolbox import assert_net_equal, create_test_network
from pandapower.timeseries import DFData
Expand Down Expand Up @@ -149,9 +149,9 @@ def test_to_json_dtypes(tmp_path):


def test_json_encoding_decoding():
net = networks.mv_oberrhein()
net = pp.networks.mv_oberrhein()
net.tuple = (1, "4")
net.mg = topology.create_nxgraph(net)
net.mg = pp.topology.create_nxgraph(net)
s = set(['1', 4])
t = tuple(['2', 3])
f = frozenset(['12', 3])
Expand Down Expand Up @@ -204,7 +204,7 @@ def test_json_tuple_in_pandas():


def test_new_pp_object_io():
net = networks.mv_oberrhein()
net = pp.networks.mv_oberrhein()
ds = DFData(pd.DataFrame(data=np.array([[0, 1, 2], [7, 8, 9]])))
pp.control.ConstControl(net, 'sgen', 'p_mw', 42, profile_name=0, data_source=ds)
pp.control.ContinuousTapControl(net, 142, 1)
Expand Down Expand Up @@ -257,22 +257,22 @@ def test_convert_format_for_pp_objects(net_in):
assert obj2.vm_upper_pu == 1.1


def test_json_io_same_net(net_in, tempdir):
def test_json_io_same_net(net_in, tmp_path):
pp.control.ConstControl(net_in, 'load', 'p_mw', 0)

s = pp.to_json(net_in)
net1 = pp.from_json_string(s)
assert net1.controller.object.at[0].net is net1

filename = os.path.join(tempdir, "testfile.json")
filename = os.path.abspath(tmp_path) + "testfile.json"
pp.to_json(net_in, filename)
net2 = pp.from_json(filename)
assert net2.controller.object.at[0].net is net2


def test_deepcopy_controller():
net = networks.mv_oberrhein()
control.ContinuousTapControl(net, 114, 1.01)
net = pp.networks.mv_oberrhein()
pp.control.ContinuousTapControl(net, 114, 1.01)
assert net == net.controller.object.iloc[0].net
net2 = copy.deepcopy(net)
assert net2 == net2.controller.object.iloc[0].net
Expand Down
2 changes: 1 addition & 1 deletion pandapower/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
create_load, create_shunt, create_bus, create_sgen
from pandapower.opf.validate_opf_input import _check_necessary_opf_parameters
from pandapower.run import runpp
from pandapower.topology import unsupplied_buses

try:
import pplog as logging
Expand Down Expand Up @@ -1233,6 +1232,7 @@ def set_isolated_areas_out_of_service(net, respect_switches=True):
"""
Set all isolated buses and all elements connected to isolated buses out of service.
"""
from pandapower.topology import unsupplied_buses
closed_switches = set()
unsupplied = unsupplied_buses(net, respect_switches=respect_switches)
logger.info("set %d of %d unsupplied buses out of service" % (
Expand Down

0 comments on commit ccb1136

Please sign in to comment.