Skip to content

Commit 7697f27

Browse files
authored
BUG: return itself when no change possible (#365)
1 parent cd0af03 commit 7697f27

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

momepy/preprocessing.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ def remove_false_nodes(gdf):
190190
"""
191191
Clean topology of existing LineString geometry by removal of nodes of degree 2.
192192
193+
Returns the original gdf if there's no node of degree 2.
194+
193195
Parameters
194196
----------
195197
gdf : GeoDataFrame, GeoSeries, array of pygeos geometries
@@ -276,6 +278,9 @@ def remove_false_nodes(gdf):
276278
)
277279
return df.append(final, ignore_index=True)
278280

281+
# if there's nothing to fix, return the original dataframe
282+
return gdf
283+
279284

280285
class CheckTessellationInput:
281286
"""

tests/test_preprocess.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from packaging.version import Version
55
from shapely import affinity
66
from shapely.geometry import LineString, MultiPoint, Polygon
7+
from geopandas.testing import assert_geodataframe_equal
78

89
import momepy as mm
910

@@ -47,6 +48,10 @@ def test_remove_false_nodes(self):
4748
assert isinstance(fixed, gpd.GeoDataFrame)
4849
assert sorted(self.false_network.columns) == sorted(fixed.columns)
4950

51+
# no node of a degree 2
52+
df = self.df_streets.drop([4, 7, 17, 22])
53+
assert_geodataframe_equal(df, mm.remove_false_nodes(df))
54+
5055
def test_CheckTessellationInput(self):
5156
df = self.df_buildings
5257
df.loc[144, "geometry"] = Polygon([(0, 0), (0, 1), (1, 0)])

0 commit comments

Comments
 (0)