Repository: martinfleis/momepy
Pull request #95 (2019-10-11 15:30:58)

BUG: SharedWallsRatio failed for non-consecutive index

codecov[bot]: # [Codecov](https://codecov.io/gh/martinfleis/momepy/pull/95?src=pr&el=h1) Report
> Merging [#95](https://codecov.io/gh/martinfleis/momepy/pull/95?src=pr&el=desc) into [master](https://codecov.io/gh/martinfleis/momepy/commit/eabf7e95972d9dfb1bc3f2644a93f11b9317d6db?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/martinfleis/momepy/pull/95/graphs/tree.svg?width=650&token=i04999UxkK&height=150&src=pr)](https://codecov.io/gh/martinfleis/momepy/pull/95?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master      #95   +/-   ##
=======================================
  Coverage   93.27%   93.27%           
=======================================
  Files           9        9           
  Lines        2439     2439           
=======================================
  Hits         2275     2275           
  Misses        164      164
```


| [Impacted Files](https://codecov.io/gh/martinfleis/momepy/pull/95?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [momepy/distribution.py](https://codecov.io/gh/martinfleis/momepy/pull/95/diff?src=pr&el=tree#diff-bW9tZXB5L2Rpc3RyaWJ1dGlvbi5weQ==) | `98.4% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/martinfleis/momepy/pull/95?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/martinfleis/momepy/pull/95?src=pr&el=footer). Last update [eabf7e9...16e18b3](https://codecov.io/gh/martinfleis/momepy/pull/95?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/momepy/distribution.py b/momepy/distribution.py
index af8612f..b6a6cf5 100644
--- a/momepy/distribution.py
+++ b/momepy/distribution.py
@@ -186,9 +186,9 @@ class SharedWallsRatio:
             unique_id = "mm_uid"
         self.id = gdf[unique_id]
 
-        for index, row in tqdm(gdf.iterrows(), total=gdf.shape[0]):
+        for i, (index, row) in tqdm(enumerate(gdf.iterrows()), total=gdf.shape[0]):
             neighbors = list(self.sindex.intersection(row.geometry.bounds))
-            neighbors.remove(index)
+            neighbors.remove(i)
 
             # if no neighbour exists
             length = 0


Test patch:
diff --git a/tests/test_distribution.py b/tests/test_distribution.py
index 45bcc98..7743d1d 100644
--- a/tests/test_distribution.py
+++ b/tests/test_distribution.py
@@ -32,10 +32,13 @@ class TestDistribution:
         self.df_buildings["swr_array"] = mm.SharedWallsRatio(
             self.df_buildings, "uID", self.df_buildings.geometry.length
         ).swr
+        nonconsecutive = self.df_buildings.drop(2)
+        result = mm.SharedWallsRatio(nonconsecutive, "uID").swr
         check = 0.3424804411228673
         assert self.df_buildings["swr"][10] == check
         assert self.df_buildings["swr_uid"][10] == check
         assert self.df_buildings["swr_array"][10] == check
+        assert result[10] == check
 
     def test_StreetAlignment(self):
         self.df_buildings["orient"] = orient = mm.Orientation(self.df_buildings).o