Skip to content

Commit

Permalink
assing self weights only when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfleis committed Mar 10, 2024
1 parent 7423380 commit 0d897cc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion momepy/functional/_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,15 @@ def building_adjacency(
Series
"""
components = contiguity_graph.component_labels
neighborhood_graph = neighborhood_graph.assign_self_weight()

# check if self-weights are present, otherwise assign them to treat self as part of
# the neighborhood
has_self_weights = (
neighborhood_graph._adjacency.index.get_level_values("focal")
== neighborhood_graph._adjacency.index.get_level_values("neighbor")
).sum() == neighborhood_graph.n
if not has_self_weights:
neighborhood_graph = neighborhood_graph.assign_self_weight()

grouper = components.loc[
neighborhood_graph._adjacency.index.get_level_values(1)
Expand Down

0 comments on commit 0d897cc

Please sign in to comment.