Repository: martinfleis/momepy
Pull request #250 (2021-01-12 17:43:59)

BUG: don't change gdf in DistanceBand + cleanup
`DistanceBand` changed geometry of original gdf. Copy is needed here.

Plus some forgotten cleanup ahead of 0.4.1 bug fix release.

codecov[bot]: # [Codecov](https://codecov.io/gh/martinfleis/momepy/pull/250?src=pr&el=h1) Report
> Merging [#250](https://codecov.io/gh/martinfleis/momepy/pull/250?src=pr&el=desc) (5dd240d) into [master](https://codecov.io/gh/martinfleis/momepy/commit/30aca9f0f59a8dca98b5859863ad051bd5ce8a55?el=desc) (30aca9f) will **decrease** coverage by `0.04%`.
> The diff coverage is `100.00%`.

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

```diff
@@            Coverage Diff             @@
##           master     #250      +/-   ##
==========================================
- Coverage   95.99%   95.95%   -0.05%     
==========================================
  Files          12       11       -1     
  Lines        2621     2593      -28     
==========================================
- Hits         2516     2488      -28     
  Misses        105      105              
```


| [Impacted Files](https://codecov.io/gh/martinfleis/momepy/pull/250?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [momepy/dimension.py](https://codecov.io/gh/martinfleis/momepy/pull/250/diff?src=pr&el=tree#diff-bW9tZXB5L2RpbWVuc2lvbi5weQ==) | `98.72% <ø> (-0.02%)` | :arrow_down: |
| [momepy/weights.py](https://codecov.io/gh/martinfleis/momepy/pull/250/diff?src=pr&el=tree#diff-bW9tZXB5L3dlaWdodHMucHk=) | `100.00% <100.00%> (+6.15%)` | :arrow_up: |
| [momepy/graph.py](https://codecov.io/gh/martinfleis/momepy/pull/250/diff?src=pr&el=tree#diff-bW9tZXB5L2dyYXBoLnB5) | `96.56% <0.00%> (-1.53%)` | :arrow_down: |
| [momepy/\_\_init\_\_.py](https://codecov.io/gh/martinfleis/momepy/pull/250/diff?src=pr&el=tree#diff-bW9tZXB5L19faW5pdF9fLnB5) | | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/martinfleis/momepy/pull/250?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/250?src=pr&el=footer). Last update [30aca9f...5dd240d](https://codecov.io/gh/martinfleis/momepy/pull/250?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/momepy/dimension.py b/momepy/dimension.py
index 3d76f53..8f04b8e 100644
--- a/momepy/dimension.py
+++ b/momepy/dimension.py
@@ -5,19 +5,15 @@
 # definitions of dimension characters
 
 import math
-from distutils.version import LooseVersion
 
-import geopandas as gpd
 import numpy as np
 import pandas as pd
 import pygeos
 import scipy as sp
-from shapely.geometry import LineString, Point
 from tqdm import tqdm
 
 from .shape import _circle_radius
 
-GPD_08 = str(gpd.__version__) >= LooseVersion("0.8.0")
 
 __all__ = [
     "Area",
diff --git a/momepy/weights.py b/momepy/weights.py
index 52bf5ce..8f83380 100644
--- a/momepy/weights.py
+++ b/momepy/weights.py
@@ -1,12 +1,8 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
-from distutils.version import LooseVersion
 
 import libpysal
 import numpy as np
-import geopandas as gpd
-
-GPD_08 = str(gpd.__version__) >= LooseVersion("0.8.0")
 
 __all__ = ["DistanceBand", "sw_high"]
 
@@ -47,24 +43,15 @@ class DistanceBand:
 
     def __init__(self, gdf, threshold, centroid=True, ids=None):
         if centroid:
+            gdf = gdf.copy()
             gdf.geometry = gdf.centroid
 
         self.neighbors = _Neighbors(gdf, threshold, ids=ids)
 
     def fetch_items(self, key):
-        if not GPD_08:
-            possible_matches_index = list(
-                self.sindex.intersection(self.bufferred[key].bounds)
-            )
-            possible_matches = self.geoms.iloc[possible_matches_index]
-            match = possible_matches.index[
-                possible_matches.intersects(self.bufferred[key])
-            ].to_list()
-            match.remove(key)
-        else:
-            hits = self.sindex.query(self.bufferred[key], predicate="intersects")
-            match = self.geoms.iloc[hits].index.to_list()
-            match.remove(key)
+        hits = self.sindex.query(self.bufferred[key], predicate="intersects")
+        match = self.geoms.iloc[hits].index.to_list()
+        match.remove(key)
         return match
 
 
@@ -79,11 +66,9 @@ class _Neighbors(dict, DistanceBand):
         self.bufferred = geoms.buffer(buffer)
         if ids:
             self.ids = np.array(geoms[ids])
-        else:
-            self.ids = range(len(self.geoms))
-        if ids:
             self.ids_bool = True
         else:
+            self.ids = range(len(self.geoms))
             self.ids_bool = False
 
     def __missing__(self, key):
diff --git a/requirements.txt b/requirements.txt
index 866df98..b7c0f44 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
-geopandas>=0.5.1
+geopandas>=0.8.0
 networkx>=2.3
 libpysal>=4.1.0
-pandas>=0.24
 tqdm>=4.25
+pygeos


Test patch:
diff --git a/tests/test_distribution.py b/tests/test_distribution.py
index 8ebe394..0cdac79 100644
--- a/tests/test_distribution.py
+++ b/tests/test_distribution.py
@@ -6,8 +6,6 @@ import numpy as np
 import pytest
 from libpysal.weights import Queen
 
-GPD_08 = str(gpd.__version__) >= LooseVersion("0.8.0")
-
 
 class TestDistribution:
     def setup_method(self):
@@ -32,7 +30,6 @@ class TestDistribution:
         check = 40.7607
         assert self.df_streets["orient"][0] == pytest.approx(check)
 
-    @pytest.mark.skipif(not GPD_08, reason="requires geopandas > 0.7")
     def test_SharedWalls(self):
         self.df_buildings["swr"] = mm.SharedWalls(self.df_buildings).series
         nonconsecutive = self.df_buildings.drop(2)
@@ -41,7 +38,6 @@ class TestDistribution:
         assert self.df_buildings["swr"][10] == check
         assert result[10] == check
 
-    @pytest.mark.skipif(not GPD_08, reason="requires geopandas > 0.7")
     def test_SharedWallsRatio(self):
         self.df_buildings["swr"] = mm.SharedWallsRatio(self.df_buildings).series
         self.df_buildings["swr_array"] = mm.SharedWallsRatio(
@@ -154,7 +150,6 @@ class TestDistribution:
             .any()
         )
 
-    @pytest.mark.skipif(not GPD_08, reason="requires geopandas > 0.7")
     def test_NeighboringStreetOrientationDeviation(self):
         self.df_streets["dev"] = mm.NeighboringStreetOrientationDeviation(
             self.df_streets
diff --git a/tests/test_weights.py b/tests/test_weights.py
index e9187aa..8965e36 100644
--- a/tests/test_weights.py
+++ b/tests/test_weights.py
@@ -45,5 +45,5 @@ class TestWeights:
 
         db_cent_false = mm.DistanceBand(self.df_buildings, 100, centroid=False)
         assert sorted(db_cent_false.neighbors[0]) == sorted(
-            [125, 133, 114, 134, 113, 121]
+            [111, 112, 115, 130, 125, 133, 114, 120, 134, 113, 121]
         )