Skip to content

Commit

Permalink
revise github_test_action.yml and package requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenMeinecke committed Nov 11, 2021
1 parent eb9d0c1 commit 0787e79
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 35 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/github_test_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ jobs:
python -m pip install --upgrade pip
python -m pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install .
pip install matplotlib python-igraph
pip install ortools
pip install .["all"]
if ${{ matrix.python-version == '3.7' }}; then python -m pip install pypower; fi
if ${{ matrix.python-version != '3.6' }}; then python -m pip install numba; fi
- name: Install Julia
Expand Down
2 changes: 1 addition & 1 deletion pandapower/io_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

import copy
import importlib
import json
Expand Down Expand Up @@ -57,7 +58,6 @@
import fiona
import fiona.crs
import geopandas

GEOPANDAS_INSTALLED = True
except ImportError:
GEOPANDAS_INSTALLED = False
Expand Down
28 changes: 10 additions & 18 deletions pandapower/plotting/generic_geodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
# Copyright (c) 2016-2021 by University of Kassel and Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel. All rights reserved.


import sys
import copy

import networkx as nx
import pandas as pd
import numpy as np

from pandapower.auxiliary import soft_dependency_error
import pandapower.topology as top

try:
Expand Down Expand Up @@ -41,14 +42,9 @@ def build_igraph_from_pp(net, respect_switches=False, buses=None):
:Example:
graph, meshed, roots = build_igraph_from_pp(net)
"""
try:
import igraph as ig
except (DeprecationWarning, ImportError):
raise ImportError("Please install python-igraph with "
"`pip install python-igraph` or "
"`conda install python-igraph` "
"or from https://www.lfd.uci.edu/~gohlke/pythonlibs")
g = ig.Graph(directed=True)
if not IGRAPH_INSTALLED:
soft_dependency_error(str(sys._getframe().f_code.co_name)+"()", "python-igraph")
g = igraph.Graph(directed=True)
bus_index = net.bus.index if buses is None else np.array(buses)
nr_buses = len(bus_index)
g.add_vertices(nr_buses)
Expand Down Expand Up @@ -111,9 +107,9 @@ def _get_element_mask_from_nodes(net, element, node_elements, nodes=None):
for node_element in node_elements:
mask &= np.isin(net[element][node_element].values, nodes)
return mask

def _get_switch_mask(net, element, switch_element, open_switches):
element_switches = net.switch.et.values == switch_element
element_switches = net.switch.et.values == switch_element
open_elements = net.switch.element.values[open_switches & element_switches]
open_element_mask = np.in1d(net[element].index, open_elements, invert=True)
return open_element_mask
Expand Down Expand Up @@ -195,11 +191,7 @@ def create_generic_coordinates(net, mg=None, library="igraph",
_prepare_geodata_table(net, geodata_table, overwrite)
if library == "igraph":
if not IGRAPH_INSTALLED:
raise UserWarning("The library igraph is selected for plotting, but not installed "
"correctly. Please install python-igraph with "
"`pip install python-igraph` or "
"`conda install python-igraph` "
"or from https://www.lfd.uci.edu/~gohlke/pythonlibs")
soft_dependency_error("build_igraph_from_pp()", "python-igraph")
graph, meshed, roots = build_igraph_from_pp(net, respect_switches, buses=buses)
coords = coords_from_igraph(graph, roots, meshed)
elif library == "networkx":
Expand All @@ -223,10 +215,10 @@ def _prepare_geodata_table(net, geodata_table, overwrite):
net[geodata_table].drop(net[geodata_table].index, inplace=True)
else:
raise UserWarning("Table %s is not empty - use overwrite=True to overwrite existing geodata"%geodata_table)

if geodata_table not in net or net[geodata_table] is None:
net[geodata_table] = pd.DataFrame(columns=["x", "y"])

def fuse_geodata(net):
mg = top.create_nxgraph(net, include_lines=False, include_impedances=False,
respect_switches=False)
Expand Down
33 changes: 32 additions & 1 deletion pandapower/plotting/geo.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
# -*- coding: utf-8 -*-

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

import sys
from numpy import array

from pandapower.auxiliary import soft_dependency_error

try:
from shapely.geometry import Point, LineString
shapely_INSTALLED = True
except ImportError:
shapely_INSTALLED = False

try:
from geopandas import GeoDataFrame, GeoSeries
geopandas_INSTALLED = True
except ImportError:
geopandas_INSTALLED = False

try:
from pyproj import Proj, transform
pyproj_INSTALLED = True
except ImportError:
pass
pyproj_INSTALLED = False


def _node_geometries_from_geodata(node_geo, epsg=31467):
Expand All @@ -17,11 +38,19 @@ def _node_geometries_from_geodata(node_geo, epsg=31467):
:type epsg: int, default 31467 (= Gauss-Krüger Zone 3)
:return: node_geodata - a geodataframe containing the node_geo and Points in the geometry column
"""
missing_packages = array(["shapely", "geopandas"])[~array([
shapely_INSTALLED, geopandas_INSTALLED])]
if len(missing_packages):
soft_dependency_error(str(sys._getframe().f_code.co_name)+"()", missing_packages)
geoms = [Point(x, y) for x, y in node_geo[["x", "y"]].values]
return GeoDataFrame(node_geo, crs=f"epsg:{epsg}", geometry=geoms, index=node_geo.index)


def _branch_geometries_from_geodata(branch_geo, epsg=31467):
missing_packages = array(["shapely", "geopandas"])[~array([
shapely_INSTALLED, geopandas_INSTALLED])]
if len(missing_packages):
soft_dependency_error(str(sys._getframe().f_code.co_name)+"()", missing_packages)
geoms = GeoSeries([LineString(x) for x in branch_geo.coords.values], index=branch_geo.index,
crs=f"epsg:{epsg}")
return GeoDataFrame(branch_geo, crs=f"epsg:{epsg}", geometry=geoms, index=branch_geo.index)
Expand Down Expand Up @@ -66,6 +95,8 @@ def _convert_xy_epsg(x, y, epsg_in=4326, epsg_out=31467):
:type epsg_out: int, default 31467 (= Gauss-Krüger Zone 3)
:return: transformed_coords - x and y values in new coordinate system
"""
if not pyproj_INSTALLED:
soft_dependency_error(str(sys._getframe().f_code.co_name)+"()", "pyproj")
in_proj = Proj(init='epsg:%i' % epsg_in)
out_proj = Proj(init='epsg:%i' % epsg_out)
return transform(in_proj, out_proj, x, y)
Expand Down
2 changes: 0 additions & 2 deletions pandapower/test/api/test_auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Copyright (c) 2016-2021 by University of Kassel and Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel. All rights reserved.


import pytest
import gc
import copy
Expand All @@ -13,7 +12,6 @@
try:
import geopandas as gpd
import shapely.geometry

GEOPANDAS_INSTALLED = True
except ImportError:
GEOPANDAS_INSTALLED = False
Expand Down
20 changes: 14 additions & 6 deletions pandapower/test/api/test_file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

import copy
import json
import os
Expand All @@ -21,8 +22,14 @@

try:
import geopandas as gpd
GEOPANDAS_INSTALLED = True
except ImportError:
GEOPANDAS_INSTALLED = False
try:
import shapely
SHAPELY_INSTALLED = True
except ImportError:
pass
SHAPELY_INSTALLED = False


@pytest.fixture(params=[1])
Expand Down Expand Up @@ -74,14 +81,16 @@ def test_json_basic(net_in, tmp_path):

def test_json_controller_none():
try:
pp.from_json(os.path.join(pp_dir, 'test', 'test_files', 'controller_containing_NoneNan.json'), convert=False)
pp.from_json(os.path.join(pp_dir, 'test', 'test_files',
'controller_containing_NoneNan.json'), convert=False)
except:
raise (UserWarning("empty net with controller containing Nan/None can't be loaded"))


def test_json(net_in, tmp_path):
filename = os.path.join(os.path.abspath(str(tmp_path)), "testfile.json")
try:

if GEOPANDAS_INSTALLED and SHAPELY_INSTALLED:
net_geo = copy.deepcopy(net_in)
# make GeodataFrame
from shapely.geometry import Point, LineString
Expand All @@ -101,8 +110,6 @@ def test_json(net_in, tmp_path):
# assert isinstance(net_out.bus_geodata, gpd.GeoDataFrame)
assert isinstance(net_out.bus_geodata.geometry.iat[0], Point)
assert isinstance(net_out.line_geodata.geometry.iat[0], LineString)
except (NameError, ImportError):
pass

# check if restore_all_dtypes works properly:
net_in.line['test'] = 123
Expand Down Expand Up @@ -371,7 +378,7 @@ def test_elements_to_deserialize_wo_keep(tmp_path):
assert_net_equal(net, net_select, name_selection=['bus', 'load'])


@pytest.mark.skipif('geopandas' not in sys.modules, reason="requires the GeoPandas library")
@pytest.mark.skipif(GEOPANDAS_INSTALLED, reason="requires the GeoPandas library")
def test_empty_geo_dataframe():
net = pp.create_empty_network()
net.bus_geodata['geometry'] = None
Expand All @@ -380,5 +387,6 @@ def test_empty_geo_dataframe():
net1 = pp.from_json_string(s)
assert assert_net_equal(net, net1)


if __name__ == "__main__":
pytest.main([__file__, "-s"])
13 changes: 9 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@
"scipy<=1.6.0",
"numpy>=0.11",
"packaging"],
# optional_requirer=["matplotlib", "geopandas", "xlsxwriter", "openpyxl", "shapely",
# "base64", "hashlib", "cryptography", "zlib"]
extras_require={
"docs": ["numpydoc", "sphinx", "sphinx_rtd_theme"],
"plotting": ["plotly", "matplotlib", "python-igraph"],
"plotting": ["plotly", "matplotlib", "python-igraph", "geopandas", "shapely", "pyproj", "base64", "hashlib", "zlib"],
"test": ["pytest", "pytest-xdist"],
"performance": ["ortools"]},
"performance": ["ortools"],
"fileio": ["xlsxwriter", "openpyxl", "cryptography", "fiona", "geopandas"],
"all": ["numpydoc", "sphinx", "sphinx_rtd_theme",
"plotly", "matplotlib", "python-igraph", "geopandas", "shapely", "pyproj", "base64", "hashlib", "zlib",
"pytest", "pytest-xdist",
"ortools",
"xlsxwriter", "openpyxl", "cryptography", "fiona" # , "geopandas" already above
]},
packages=find_packages(),
include_package_data=True,
classifiers=classifiers
Expand Down

0 comments on commit 0787e79

Please sign in to comment.