Skip to content

Commit

Permalink
TST: update for changes in GEOS (#638)
Browse files Browse the repository at this point in the history
* TST: update for changes in GEOS

* docstrings

* partial revert

* try fixing the dev failure

* rm tests
  • Loading branch information
martinfleis authored Jul 9, 2024
1 parent be2b0dd commit c91635e
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 95 deletions.
26 changes: 13 additions & 13 deletions momepy/functional/_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,11 @@ def weighted_character(
>>> elongation = momepy.elongation(buildings)
>>> elongation.head()
0 0.908235
1 0.581317
2 0.726515
3 0.838843
4 0.727297
0 0.908244
1 0.581318
2 0.726527
3 0.838840
4 0.727294
Name: elongation, dtype: float64
Define spatial graph:
Expand All @@ -360,16 +360,16 @@ def weighted_character(
>>> momepy.weighted_character(elongation, buildings.area, knn5)
focal
0 0.808188
1 0.817300
2 0.627588
3 0.794766
4 0.806400
...
139 0.780764
0 0.808190
1 0.817309
2 0.627589
3 0.794769
4 0.806403
...
139 0.780744
140 0.875046
141 0.753670
142 0.440009
142 0.440000
143 0.901127
Name: sum, Length: 144, dtype: float64
"""
Expand Down
68 changes: 34 additions & 34 deletions momepy/functional/_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ def orientation(geometry: GeoDataFrame | GeoSeries) -> Series:
>>> path = momepy.datasets.get_path("bubenec")
>>> buildings = geopandas.read_file(path, layer="buildings")
>>> momepy.orientation(buildings)
0 41.050525
0 41.051468
1 20.829200
2 20.967704
3 20.811290
4 20.411651
...
139 21.110547
2 20.969610
3 20.811525
4 20.412895
...
139 21.107057
140 13.669062
141 13.671225
141 13.671217
142 21.463914
143 13.754569
Name: orientation, Length: 144, dtype: float64
Expand Down Expand Up @@ -185,17 +185,17 @@ def alignment(orientation: Series, graph: Graph) -> Series:
Alignment of orienation within triangulated neighbors:
>>> momepy.alignment(orientation, delaunay)
0 14.638740
1 0.217086
2 0.204713
3 0.151303
4 0.353203
...
139 1.970563
140 0.127318
141 0.161911
142 4.351755
143 0.084888
0 14.639585
1 0.217417
2 0.205626
3 0.151730
4 0.352692
...
139 1.970642
140 0.127322
141 0.161906
142 4.350890
143 0.084884
Name: alignment, Length: 144, dtype: float64
"""
orientation_expanded = orientation.loc[graph._adjacency.index.get_level_values(1)]
Expand Down Expand Up @@ -584,15 +584,15 @@ def street_alignment(
Compute street alignment.
>>> momepy.street_alignment(blg_orient, str_orient, buildings["street_index"])
0 0.289796
0 0.290739
1 4.542071
2 0.107651
3 0.425138
4 0.824776
2 0.105745
3 0.424903
4 0.823533
...
139 1.783366
139 1.779876
140 0.109254
141 0.466462
141 0.466453
142 1.223387
143 0.455081
Name: street_alignment, Length: 144, dtype: float64
Expand Down Expand Up @@ -644,17 +644,17 @@ def cell_alignment(
Compute alignment:
>>> momepy.cell_alignment(blg_orient, tess_orient)
0 0.853584
1 20.829171
2 5.550296
3 4.052898
4 0.160534
...
139 0.193781
140 17.920319
0 0.854788
1 20.829200
2 5.552120
3 4.052674
4 0.159289
...
139 0.189750
140 17.920139
141 0.393708
142 0.023874
143 0.252116
142 0.024618
143 0.252122
Name: orientation, Length: 144, dtype: float64
"""

Expand Down
42 changes: 21 additions & 21 deletions momepy/functional/_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,16 +379,16 @@ def rectangularity(geometry: GeoDataFrame | GeoSeries) -> Series:
>>> path = momepy.datasets.get_path("bubenec")
>>> buildings = geopandas.read_file(path, layer="buildings")
>>> momepy.rectangularity(buildings)
0 0.694257
1 0.702243
2 0.901606
3 0.821808
4 0.912861
...
139 0.997022
0 0.694268
1 0.702242
2 0.901582
3 0.821797
4 0.912858
...
139 0.996876
140 0.820865
141 0.659281
142 0.971584
142 0.971600
143 0.999400
Length: 144, dtype: float64
"""
Expand Down Expand Up @@ -612,14 +612,14 @@ def equivalent_rectangular_index(geometry: GeoDataFrame | GeoSeries) -> Series:
>>> momepy.equivalent_rectangular_index(buildings)
0 0.787923
1 0.443137
2 0.954253
2 0.954252
3 0.851658
4 0.957543
...
139 1.000055
...
139 1.000050
140 0.907837
141 0.813269
142 0.995923
142 0.995926
143 0.999999
Length: 144, dtype: float64
"""
Expand Down Expand Up @@ -656,17 +656,17 @@ def elongation(geometry: GeoDataFrame | GeoSeries) -> Series:
>>> path = momepy.datasets.get_path("bubenec")
>>> buildings = geopandas.read_file(path, layer="buildings")
>>> momepy.elongation(buildings)
0 0.908235
1 0.581317
2 0.726515
3 0.838843
4 0.727297
...
139 0.607978
0 0.908244
1 0.581318
2 0.726527
3 0.838840
4 0.727294
...
139 0.608004
140 0.979998
141 0.747326
142 0.564071
143 0.987954
142 0.564060
143 0.987953
Name: elongation, Length: 144, dtype: float64
"""
bbox = shapely.minimum_rotated_rectangle(geometry.geometry.array)
Expand Down
4 changes: 2 additions & 2 deletions momepy/functional/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from pandas.testing import assert_index_equal


def assert_result(result, expected, geometry, **kwargs):
def assert_result(result, expected, geometry, rel=None, abs=None, **kwargs): # noqa: A002
"""Check the expected values and types of the result.
Note: ''count'' refers to the number of non-NAs in the result."""
for key, value in expected.items():
assert getattr(result, key)() == pytest.approx(value)
assert getattr(result, key)() == pytest.approx(value, rel=rel, abs=abs)
assert isinstance(result, pd.Series)
assert_index_equal(result.index, geometry.index, **kwargs)

Expand Down
8 changes: 4 additions & 4 deletions momepy/functional/tests/test_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_orientation(self):
"max": 42.329365250279125,
}
r = mm.orientation(self.df_buildings)
assert_result(r, expected, self.df_buildings)
assert_result(r, expected, self.df_buildings, rel=1e-4)

expected = {
"mean": 21.176405050561755,
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_alignment(self):
"max": 21.32311946014944,
}
r = mm.alignment(orientation, self.graph)
assert_result(r, expected, self.df_buildings, check_names=False)
assert_result(r, expected, self.df_buildings, check_names=False, rel=1e-4)

def test_neighbor_distance(self):
expected = {
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_street_alignment(self):
"max": 20.357934749623894,
}
r = mm.street_alignment(building_orientation, street_orientation, street_index)
assert_result(r, expected, self.df_buildings)
assert_result(r, expected, self.df_buildings, rel=1e-3)

def test_cell_alignment(self):
df_buildings = self.df_buildings.reset_index()
Expand All @@ -136,7 +136,7 @@ def test_cell_alignment(self):
"max": 33.201625570390746,
"min": 1.722848278973288e-05,
}
assert_result(align, align_expected, df_buildings)
assert_result(align, align_expected, df_buildings, abs=1e-2)
assert_series_equal(align, align2, check_names=False)


Expand Down
18 changes: 0 additions & 18 deletions momepy/functional/tests/test_diversity.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,6 @@ def test_unique(self):
un_nan_drop, un_nan_drop_expected, self.df_tessellation, check_names=False
)

# to count nas you have to explicitly process them npw
self.df_tessellation.loc[self.df_tessellation["cat"].isna(), "cat"] = "np.nan"
un_nan = self.diversity_graph.describe(
self.df_tessellation["cat"], statistics=["nunique"]
)["nunique"]
un_nan_expected = {"count": 144, "mean": 8.13888888888889, "min": 8, "max": 9}
assert_result(un_nan, un_nan_expected, self.df_tessellation, check_names=False)

@pytest.mark.skipif(
not PD_210, reason="aggregation is different in previous pandas versions"
)
Expand Down Expand Up @@ -1092,16 +1084,6 @@ def test_unique(self):
).series
assert_series_equal(un_new, un_old, check_dtype=False, check_names=False)

# to keep NAs you ahve to explicitly process them now
self.df_tessellation.loc[self.df_tessellation["cat"].isna(), "cat"] = "np.nan"
un_new = self.graph_diversity.describe(
self.df_tessellation["cat"], statistics=["nunique"]
)["nunique"]
un_old = mm.Unique(
self.df_tessellation, "cat", self.sw, "uID", dropna=False
).series
assert_series_equal(un_new, un_old, check_dtype=False, check_names=False)

def test_unweighted_percentile(self):
sw = mm.sw_high(k=3, gdf=self.df_tessellation, ids="uID")
graph = (
Expand Down
4 changes: 2 additions & 2 deletions momepy/functional/tests/test_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_rectangularity(self):
"max": 0.9994000284783504,
}
r = mm.rectangularity(self.df_buildings)
assert_result(r, expected, self.df_buildings)
assert_result(r, expected, self.df_buildings, rel=1e-3)

def test_shape_index(self):
expected = {
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_elongation(self):
"max": 0.9975111632520667,
}
r = mm.elongation(self.df_buildings)
assert_result(r, expected, self.df_buildings)
assert_result(r, expected, self.df_buildings, rel=1e-3)

@pytest.mark.skipif(not GPD_013, reason="get_coordinates() not available")
def test_centroid_corner_distance(self):
Expand Down
2 changes: 1 addition & 1 deletion momepy/tests/test_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_Alignment(self):
if Version(shapely.geos_version_string) < Version("3.12")
else 18.29842494
)
assert self.df_buildings["align_sw"][0] == pytest.approx(test_value)
assert self.df_buildings["align_sw"][0] == pytest.approx(test_value, rel=1e-3)
sw_drop = Queen.from_dataframe(self.df_tessellation[2:], ids="uID")
assert (
mm.Alignment(self.df_buildings, sw_drop, "uID", self.df_buildings["orient"])
Expand Down

0 comments on commit c91635e

Please sign in to comment.