Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix failing tests due to the precision changes #2437

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 48 additions & 10 deletions pandapower/test/plotting/test_geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import geojson
import pandas as pd
import pytest
from pandas.testing import assert_frame_equal, assert_index_equal

import pandapower.plotting.geo as geo
from pandapower.test.helper_functions import create_test_network
Expand Down Expand Up @@ -54,50 +55,89 @@ def get_network_and_result(net, request):

def test__node_geometries_from_geodata(get_network_and_result):
pytest.importorskip("geopandas")
from geopandas import testing

_net, expected = get_network_and_result
_bus_geojson_to_geodata_(_net)

result = geo._node_geometries_from_geodata(_net.bus_geodata)
testing.assert_geodataframe_equal(result, expected)
# is mostly the same as assert_geodataframe_equal with check_less_precise=True, but the tolerance in the function
# can't be adapted
assert result.shape == expected.shape
assert isinstance(result, type(expected))
assert (result.geom_equals_exact(expected.geometry, tolerance=1 * 10 ** (-6)) |
(result.geometry.is_empty & expected.geometry.is_empty) |
(result.geometry.isna() & expected.geometry.isna())).all()
left2 = result.select_dtypes(exclude="geometry")
right2 = expected.select_dtypes(exclude="geometry")
assert_index_equal(result.columns, expected.columns, exact="equiv", obj="GeoDataFrame.columns")
assert_frame_equal(left2, right2, check_dtype=True, check_index_type="equiv", check_column_type="equiv", obj="GeoDataFrame")


def test__branch_geometries_from_geodata(get_network_and_result):
pytest.importorskip("geopandas")
from geopandas import testing

_net, expected = get_network_and_result

_line_geojson_to_geodata_(_net)

result = geo._branch_geometries_from_geodata(_net.line_geodata)
testing.assert_geodataframe_equal(result, expected)
# is mostly the same as assert_geodataframe_equal with check_less_precise=True, but the tolerance in the function
# can't be adapted
assert result.shape == expected.shape
assert isinstance(result, type(expected))
assert (result.geom_equals_exact(expected.geometry, tolerance=1 * 10 ** (-6)) |
(result.geometry.is_empty & expected.geometry.is_empty) |
(result.geometry.isna() & expected.geometry.isna())).all()
left2 = result.select_dtypes(exclude="geometry")
right2 = expected.select_dtypes(exclude="geometry")
assert_index_equal(result.columns, expected.columns, exact="equiv", obj="GeoDataFrame.columns")
assert_frame_equal(left2, right2, check_dtype=True, check_index_type="equiv", check_column_type="equiv",
obj="GeoDataFrame")


def test__transform_node_geometry_to_geodata(get_network_and_result):
pytest.importorskip("geopandas")
from geopandas import testing

_net, expected = get_network_and_result
_bus_geojson_to_geodata_(_net)

# Transforming to geodata to test the inverse...
_net.bus_geodata = geo._node_geometries_from_geodata(_net.bus_geodata)
result = geo._transform_node_geometry_to_geodata(_net.bus_geodata)
testing.assert_geodataframe_equal(result, expected)
# is mostly the same as assert_geodataframe_equal with check_less_precise=True, but the tolerance in the function
# can't be adapted
assert result.shape == expected.shape
assert isinstance(result, type(expected))
assert (result.geom_equals_exact(expected.geometry, tolerance=1 * 10 ** (-6)) |
(result.geometry.is_empty & expected.geometry.is_empty) |
(result.geometry.isna() & expected.geometry.isna())).all()
left2 = result.select_dtypes(exclude="geometry")
right2 = expected.select_dtypes(exclude="geometry")
assert_index_equal(result.columns, expected.columns, exact="equiv", obj="GeoDataFrame.columns")
assert_frame_equal(left2, right2, check_dtype=True, check_index_type="equiv", check_column_type="equiv",
obj="GeoDataFrame")


def test__transform_branch_geometry_to_coords(get_network_and_result):
pytest.importorskip("geopandas")
from geopandas import testing

_net, expected = get_network_and_result
_line_geojson_to_geodata_(_net)

_net.line_geodata = geo._branch_geometries_from_geodata(_net.line_geodata)
result = geo._transform_branch_geometry_to_coords(_net.line_geodata)
testing.assert_geodataframe_equal(result, expected)
# is mostly the same as assert_geodataframe_equal with check_less_precise=True, but the tolerance in the function
# can't be adapted
assert result.shape == expected.shape
assert isinstance(result, type(expected))
assert (result.geom_equals_exact(expected.geometry, tolerance=1 * 10 ** (-6)) |
(result.geometry.is_empty & expected.geometry.is_empty) |
(result.geometry.isna() & expected.geometry.isna())).all()
left2 = result.select_dtypes(exclude="geometry")
right2 = expected.select_dtypes(exclude="geometry")
assert_index_equal(result.columns, expected.columns, exact="equiv", obj="GeoDataFrame.columns")
assert_frame_equal(left2, right2, check_dtype=True, check_index_type="equiv", check_column_type="equiv",
obj="GeoDataFrame")


def test__convert_xy_epsg():
Expand Down Expand Up @@ -261,7 +301,6 @@ def test_dump_to_geojson():
assert dumps(result, sort_keys=True) == '{"features": [{"geometry": {"coordinates": [[1.0, 2.0], [3.0, 4.0]], "type": "LineString"}, "id": "line-0", "properties": {"c_nf_per_km": 720.0, "df": 1.0, "from_bus": 1, "g_us_per_km": 0.0, "i_from_ka": 7.0, "i_ka": 7.0, "i_to_ka": 7.0, "ices": 0.389985, "in_service": true, "length_km": 1.0, "loading_percent": 7.0, "max_i_ka": 0.328, "name": "line1", "p_from_mw": 7.0, "p_to_mw": 7.0, "parallel": 1, "pl_mw": 7.0, "pp_index": 0, "pp_type": "line", "q_from_mvar": 7.0, "q_to_mvar": 7.0, "ql_mvar": 7.0, "r_ohm_per_km": 0.2067, "std_type": null, "to_bus": 7, "type": null, "va_from_degree": 7.0, "va_to_degree": 7.0, "vm_from_pu": 7.0, "vm_to_pu": 7.0, "x_ohm_per_km": 0.1897522}, "type": "Feature"}], "type": "FeatureCollection"}'



def test_convert_geodata_to_geojson():
pytest.importorskip("geojson")
pytest.importorskip("pandapower")
Expand Down Expand Up @@ -295,6 +334,5 @@ def test_convert_gis_to_geojson():
pytest.skip("Not implemented")



if __name__ == "__main__":
pytest.main(["test_geo.py"])
Loading