Skip to content

Commit

Permalink
REF: do not return building_id from generate_blocks (#627)
Browse files Browse the repository at this point in the history
* remove buildings_id

* docstring
  • Loading branch information
u3ks committed Jun 20, 2024
1 parent 9a64a1a commit 81ba419
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
17 changes: 7 additions & 10 deletions momepy/functional/_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,12 @@ def get_nearest_node(

def generate_blocks(
tessellation: GeoDataFrame, edges: GeoDataFrame, buildings: GeoDataFrame
) -> tuple[GeoDataFrame, Series, Series]:
) -> tuple[GeoDataFrame, Series]:
"""
Generate blocks based on buildings, tessellation, and street network.
Dissolves tessellation cells based on street-network based polygons.
Links resulting ID to ``buildings`` and ``tessellation`` and returns
``blocks``, ``buildings_ds`` and ``tessellation`` ids.
Links resulting ID to ``tessellation`` and returns
``blocks`` and ``tessellation`` ids.
Parameters
----------
Expand All @@ -588,8 +588,6 @@ def generate_blocks(
-------
blocks : GeoDataFrame
A GeoDataFrame containing generated blocks.
buildings_ids : Series
A Series derived from buildings with block ID.
tessellation_ids : Series
A Series derived from morphological tessellation with block ID.
Expand All @@ -610,7 +608,7 @@ def generate_blocks(
3 POLYGON ((1602995.269 6464132.007, 1603001.768...
4 POLYGON ((1603084.231 6464104.386, 1603083.773...
>>> blocks, buildings_id, tessellation_id = momepy.generate_blocks(
>>> blocks, tessellation_id = momepy.generate_blocks(
... tessellation, streets, buildings
... )
>>> blocks.head()
Expand All @@ -621,10 +619,9 @@ def generate_blocks(
3 POLYGON ((1603137.411 6464124.658, 1603137.116...
4 POLYGON ((1603179.384 6463961.584, 1603179.357...
Both ``buildings_id`` and ``tessellation_id`` can be directly assigned to their
respective parental DataFrames.
``tessellation_id`` can be directly assigned to its
respective parental DataFrame directly.
>>> buildings["block_id"] = buildings_id
>>> tessellation["block_id"] = tessellation_id
"""

Expand Down Expand Up @@ -670,7 +667,7 @@ def generate_blocks(
)
tessellation_id = cells_m[id_name]

return blocks, buildings_id, tessellation_id
return blocks, tessellation_id


def buffered_limit(
Expand Down
12 changes: 6 additions & 6 deletions momepy/functional/tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,10 @@ def test_buffered_limit_error(self):
mm.buffered_limit(self.df_buildings, "invalid")

def test_blocks(self):
blocks, buildings_id, tessellation_id = mm.generate_blocks(
blocks, tessellation_id = mm.generate_blocks(
self.df_tessellation, self.df_streets, self.df_buildings
)
assert not tessellation_id.isna().any()
assert not buildings_id.isna().any()
assert len(blocks) == 8

def test_blocks_inner(self):
Expand All @@ -321,11 +320,10 @@ def test_blocks_inner(self):
.buffer(20)
.exterior
)
blocks, buildings_id, tessellation_id = mm.generate_blocks(
blocks, tessellation_id = mm.generate_blocks(
self.df_tessellation, streets, self.df_buildings
)
assert not tessellation_id.isna().any()
assert not buildings_id.isna().any()
assert len(blocks) == 9
if GPD_GE_013:
assert len(blocks.sindex.query(blocks.geometry, "overlaps")[0]) == 0
Expand Down Expand Up @@ -400,7 +398,7 @@ def setup_method(self):
)

def test_blocks(self):
blocks, buildings_id, tessellation_id = mm.generate_blocks(
blocks, tessellation_id = mm.generate_blocks(
self.df_tessellation, self.df_streets, self.df_buildings
)
res = mm.Blocks(
Expand All @@ -410,5 +408,7 @@ def test_blocks(self):
assert_geodataframe_equal(
blocks.geometry.to_frame(), res.blocks.geometry.to_frame()
)
assert_series_equal(buildings_id, res.buildings_id)
assert_series_equal(
tessellation_id[tessellation_id.index >= 0], res.buildings_id
)
assert_series_equal(tessellation_id, res.tessellation_id)

0 comments on commit 81ba419

Please sign in to comment.