venv
This commit is contained in:
@@ -3,14 +3,15 @@ import os
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
from shapely.geometry import Point, Polygon, LineString, GeometryCollection, box
|
||||
from shapely import make_valid
|
||||
from shapely.geometry import GeometryCollection, LineString, Point, Polygon, box
|
||||
|
||||
import geopandas
|
||||
from geopandas import GeoDataFrame, GeoSeries, overlay, read_file
|
||||
from geopandas._compat import PANDAS_GE_20
|
||||
from geopandas._compat import HAS_PYPROJ, PANDAS_GE_20
|
||||
|
||||
from geopandas.testing import assert_geodataframe_equal, assert_geoseries_equal
|
||||
import pytest
|
||||
from geopandas.testing import assert_geodataframe_equal, assert_geoseries_equal
|
||||
|
||||
try:
|
||||
from fiona.errors import DriverError
|
||||
@@ -23,9 +24,6 @@ except ImportError:
|
||||
DATA = os.path.join(os.path.abspath(os.path.dirname(__file__)), "data", "overlay")
|
||||
|
||||
|
||||
pytestmark = pytest.mark.skip_no_sindex
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dfs(request):
|
||||
s1 = GeoSeries(
|
||||
@@ -83,7 +81,7 @@ def test_overlay(dfs_index, how):
|
||||
expected = read_file(
|
||||
os.path.join(DATA, "polys", "df1_df2-{0}.geojson".format(name))
|
||||
)
|
||||
expected.crs = None
|
||||
expected.geometry.array.crs = None
|
||||
for col in expected.columns[expected.dtypes == "int32"]:
|
||||
expected[col] = expected[col].astype("int64")
|
||||
return expected
|
||||
@@ -115,8 +113,8 @@ def test_overlay(dfs_index, how):
|
||||
|
||||
|
||||
@pytest.mark.filterwarnings("ignore:GeoSeries crs mismatch:UserWarning")
|
||||
def test_overlay_nybb(how):
|
||||
polydf = read_file(geopandas.datasets.get_path("nybb"))
|
||||
def test_overlay_nybb(how, nybb_filename):
|
||||
polydf = read_file(nybb_filename)
|
||||
|
||||
# The circles have been constructed and saved at the time the expected
|
||||
# results were created (exact output of buffer algorithm can slightly
|
||||
@@ -212,6 +210,10 @@ def test_overlay_nybb(how):
|
||||
expected.loc[24, "geometry"] = None
|
||||
result.loc[24, "geometry"] = None
|
||||
|
||||
# missing values get read as None in read_file for a string column, but
|
||||
# are introduced as NaN by overlay
|
||||
expected["BoroName"] = expected["BoroName"].fillna(np.nan)
|
||||
|
||||
assert_geodataframe_equal(
|
||||
result,
|
||||
expected,
|
||||
@@ -347,6 +349,7 @@ def test_geoseries_warning(dfs):
|
||||
overlay(df1, df2.geometry, how="union")
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_PYPROJ, reason="pyproj not available")
|
||||
def test_preserve_crs(dfs, how):
|
||||
df1, df2 = dfs
|
||||
result = overlay(df1, df2, how=how)
|
||||
@@ -358,6 +361,7 @@ def test_preserve_crs(dfs, how):
|
||||
assert result.crs == crs
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_PYPROJ, reason="pyproj not available")
|
||||
def test_crs_mismatch(dfs, how):
|
||||
df1, df2 = dfs
|
||||
df1.crs = 4326
|
||||
@@ -514,6 +518,12 @@ def test_overlay_strict(how, keep_geom_type, geom_types):
|
||||
expected = expected.sort_values(cols, axis=0).reset_index(drop=True)
|
||||
result = result.sort_values(cols, axis=0).reset_index(drop=True)
|
||||
|
||||
# some columns are all-NaN in the result, but get read as object dtype
|
||||
# column of None values in read_file
|
||||
for col in ["col1", "col3", "col4"]:
|
||||
if col in expected.columns and expected[col].isna().all():
|
||||
expected[col] = expected[col].astype("float64")
|
||||
|
||||
assert_geodataframe_equal(
|
||||
result,
|
||||
expected,
|
||||
@@ -693,11 +703,11 @@ def test_keep_geom_type_geometry_collection_difference():
|
||||
assert_geodataframe_equal(result1, expected1)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("make_valid", [True, False])
|
||||
def test_overlap_make_valid(make_valid):
|
||||
@pytest.mark.parametrize("should_make_valid", [True, False])
|
||||
def test_overlap_make_valid(should_make_valid):
|
||||
bowtie = Polygon([(1, 1), (9, 9), (9, 1), (1, 9), (1, 1)])
|
||||
assert not bowtie.is_valid
|
||||
fixed_bowtie = bowtie.buffer(0)
|
||||
fixed_bowtie = make_valid(bowtie)
|
||||
assert fixed_bowtie.is_valid
|
||||
|
||||
df1 = GeoDataFrame({"col1": ["region"], "geometry": GeoSeries([box(0, 0, 10, 10)])})
|
||||
@@ -705,17 +715,17 @@ def test_overlap_make_valid(make_valid):
|
||||
{"col1": ["invalid", "valid"], "geometry": GeoSeries([bowtie, fixed_bowtie])}
|
||||
)
|
||||
|
||||
if make_valid:
|
||||
df_overlay_bowtie = overlay(df1, df_bowtie, make_valid=make_valid)
|
||||
if should_make_valid:
|
||||
df_overlay_bowtie = overlay(df1, df_bowtie, make_valid=should_make_valid)
|
||||
assert df_overlay_bowtie.at[0, "geometry"].equals(fixed_bowtie)
|
||||
assert df_overlay_bowtie.at[1, "geometry"].equals(fixed_bowtie)
|
||||
else:
|
||||
with pytest.raises(ValueError, match="1 invalid input geometries"):
|
||||
overlay(df1, df_bowtie, make_valid=make_valid)
|
||||
overlay(df1, df_bowtie, make_valid=should_make_valid)
|
||||
|
||||
|
||||
def test_empty_overlay_return_non_duplicated_columns():
|
||||
nybb = geopandas.read_file(geopandas.datasets.get_path("nybb"))
|
||||
def test_empty_overlay_return_non_duplicated_columns(nybb_filename):
|
||||
nybb = geopandas.read_file(nybb_filename)
|
||||
nybb2 = nybb.copy()
|
||||
nybb2.geometry = nybb2.translate(20000000)
|
||||
|
||||
@@ -854,7 +864,7 @@ class TestOverlayWikiExample:
|
||||
|
||||
def test_intersection(self):
|
||||
df_result = overlay(self.layer_a, self.layer_b, how="intersection")
|
||||
assert df_result.geom_equals(self.intersection).bool()
|
||||
assert df_result.geom_equals(self.intersection).all()
|
||||
|
||||
def test_union(self):
|
||||
df_result = overlay(self.layer_a, self.layer_b, how="union")
|
||||
|
||||
Reference in New Issue
Block a user