From ccb1136e1d40bac8141c61e915e642f0ff81068d Mon Sep 17 00:00:00 2001 From: Alexander Scheidler Date: Sun, 29 Mar 2020 08:54:21 +0200 Subject: [PATCH] fixes import bug --- pandapower/convert_format.py | 3 +-- pandapower/diagnostic.py | 5 +---- pandapower/diagnostic_reports.py | 12 ++++++------ pandapower/test/api/test_file_io.py | 20 ++++++++++---------- pandapower/toolbox.py | 2 +- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/pandapower/convert_format.py b/pandapower/convert_format.py index 8e407dc20..7e39be823 100644 --- a/pandapower/convert_format.py +++ b/pandapower/convert_format.py @@ -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) diff --git a/pandapower/diagnostic.py b/pandapower/diagnostic.py index dd95ebc0b..2237e5b0a 100644 --- a/pandapower/diagnostic.py +++ b/pandapower/diagnostic.py @@ -4,8 +4,6 @@ # and Energy System Technology (IEE), Kassel. All rights reserved. - - import copy import pandas as pd import numpy as np @@ -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 @@ -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 = [] diff --git a/pandapower/diagnostic_reports.py b/pandapower/diagnostic_reports.py index 26c95a60d..fa2dcc357 100644 --- a/pandapower/diagnostic_reports.py +++ b/pandapower/diagnostic_reports.py @@ -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") @@ -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: @@ -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." @@ -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])) @@ -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])) @@ -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])) diff --git a/pandapower/test/api/test_file_io.py b/pandapower/test/api/test_file_io.py index 4ec20e076..d41f1eff8 100644 --- a/pandapower/test/api/test_file_io.py +++ b/pandapower/test/api/test_file_io.py @@ -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 @@ -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]) @@ -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) @@ -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 diff --git a/pandapower/toolbox.py b/pandapower/toolbox.py index 91713414a..7b3fb2c7c 100644 --- a/pandapower/toolbox.py +++ b/pandapower/toolbox.py @@ -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 @@ -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" % (