nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: martinfleis/momepy
Pull request #23 (2019-07-10 15:03:01)

BUG: get_network_id() fails if set nID is already in elements


Patch:
diff --git a/momepy/elements.py b/momepy/elements.py
index b160749..520b325 100644
--- a/momepy/elements.py
+++ b/momepy/elements.py
@@ -809,6 +809,9 @@ def get_network_id(elements, streets, unique_id, network_id, min_size=100):
 
     print('Generating centroids...')
     buildings_c = elements.copy()
+    if network_id in buildings_c.columns:
+        buildings_c = buildings_c.drop([network_id], axis=1)
+
     buildings_c['geometry'] = buildings_c.centroid  # make centroids
 
     print('Generating list of points...')
@@ -841,7 +844,11 @@ def get_network_id(elements, streets, unique_id, network_id, min_size=100):
     cleaned = joined[[unique_id, network_id]]
 
     print('Merging with elements...')
-    elements_m = elements.merge(cleaned, on=unique_id)
+    if network_id in elements.columns:
+        elements_copy = elements.copy().drop([network_id], axis=1)
+        elements_m = elements_copy.merge(cleaned, on=unique_id)
+    else:
+        elements_m = elements.merge(cleaned, on=unique_id)
 
     if elements_m[network_id].isnull().any():
         import warnings


Test patch:
diff --git a/tests/test_elements.py b/tests/test_elements.py
index b908262..01221ea 100644
--- a/tests/test_elements.py
+++ b/tests/test_elements.py
@@ -34,6 +34,11 @@ class TestElements:
         buildings_id = mm.get_network_id(self.df_buildings, self.df_streets, 'uID', 'nID')
         assert not buildings_id.isna().any()
 
+    def test_get_network_id_duplicate(self):
+        self.df_buildings['nID'] = range(len(self.df_buildings))
+        buildings_id = mm.get_network_id(self.df_buildings, self.df_streets, 'uID', 'nID')
+        assert not buildings_id.isna().any()
+
     def test_get_node_id(self):
         nx = mm.gdf_to_nx(self.df_streets)
         nodes, edges = mm.nx_to_gdf(nx)
Repository: martinfleis/momepy
Pull request #83 (2019-09-23 16:03:53)

BUG: sw from nx_to_gdf were non-binary in some cases


Patch:
diff --git a/momepy/shape.py b/momepy/shape.py
index 3de0967..702c0fd 100644
--- a/momepy/shape.py
+++ b/momepy/shape.py
@@ -401,6 +401,8 @@ def _cross_product(x0, y0, x1, y1, x2, y2):
 
 # calculate the area of circumcircle
 def _circle_area(points):
+    if len(points[0]) == 3:
+        points = [x[:2] for x in points]
     circ = _make_circle(points)
     return math.pi * circ[2] ** 2
 
diff --git a/momepy/utils.py b/momepy/utils.py
index 11beed2..d775432 100644
--- a/momepy/utils.py
+++ b/momepy/utils.py
@@ -259,6 +259,7 @@ def _primal_to_gdf(net, points, lines, spatial_weights, nodeID):
 
         if spatial_weights is True:
             W = libpysal.weights.W.from_networkx(net)
+            W.transform = "b"
 
     if lines is True:
         gdf_edges = _lines_to_gdf(net, lines, points, nodeID)


Test patch:
diff --git a/tests/test_shape.py b/tests/test_shape.py
index c927684..0fd17da 100644
--- a/tests/test_shape.py
+++ b/tests/test_shape.py
@@ -4,7 +4,7 @@ import geopandas as gpd
 import momepy as mm
 import numpy as np
 from momepy.shape import _circle_area
-from shapely.geometry import Point
+from shapely.geometry import Point, Polygon
 
 
 class TestShape:
@@ -211,3 +211,8 @@ class TestShape:
         check = 26.32772969906327
         assert self.df_buildings["cwa"][0] == check
         assert self.df_buildings["cwa_array"][0] == check
+
+    def test__circle_area(self):
+        poly = Polygon([(0, 1, 0), (1, 1, 0), (2, 4, 0)])
+        check = _circle_area(poly.exterior.coords)
+        assert check == 10.210176124166827
Repository: martinfleis/momepy
Pull request #84 (2019-09-23 16:21:32)

BUG: support Polygon Z

codecov[bot]: # [Codecov](https://codecov.io/gh/martinfleis/momepy/pull/84?src=pr&el=h1) Report
> Merging [#84](https://codecov.io/gh/martinfleis/momepy/pull/84?src=pr&el=desc) into [master](https://codecov.io/gh/martinfleis/momepy/commit/398c0d62900c9f025c2c795489d550ef8c1aff49?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master      #84      +/-   ##
==========================================
+ Coverage   93.21%   93.22%   +<.01%     
==========================================
  Files           9        9              
  Lines        2417     2419       +2     
==========================================
+ Hits         2253     2255       +2     
  Misses        164      164
```


| [Impacted Files](https://codecov.io/gh/martinfleis/momepy/pull/84?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [momepy/shape.py](https://codecov.io/gh/martinfleis/momepy/pull/84/diff?src=pr&el=tree#diff-bW9tZXB5L3NoYXBlLnB5) | `95.24% <100%> (+0.02%)` | :arrow_up: |

------

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


Patch:
diff --git a/momepy/shape.py b/momepy/shape.py
index 3de0967..702c0fd 100644
--- a/momepy/shape.py
+++ b/momepy/shape.py
@@ -401,6 +401,8 @@ def _cross_product(x0, y0, x1, y1, x2, y2):
 
 # calculate the area of circumcircle
 def _circle_area(points):
+    if len(points[0]) == 3:
+        points = [x[:2] for x in points]
     circ = _make_circle(points)
     return math.pi * circ[2] ** 2
 


Test patch:
diff --git a/tests/test_shape.py b/tests/test_shape.py
index c927684..0fd17da 100644
--- a/tests/test_shape.py
+++ b/tests/test_shape.py
@@ -4,7 +4,7 @@ import geopandas as gpd
 import momepy as mm
 import numpy as np
 from momepy.shape import _circle_area
-from shapely.geometry import Point
+from shapely.geometry import Point, Polygon
 
 
 class TestShape:
@@ -211,3 +211,8 @@ class TestShape:
         check = 26.32772969906327
         assert self.df_buildings["cwa"][0] == check
         assert self.df_buildings["cwa_array"][0] == check
+
+    def test__circle_area(self):
+        poly = Polygon([(0, 1, 0), (1, 1, 0), (2, 4, 0)])
+        check = _circle_area(poly.exterior.coords)
+        assert check == 10.210176124166827
Repository: martinfleis/momepy
Pull request #99 (2019-10-19 09:25:58)

ENH: reimplement local_betweenness_centrality
Reimplemented ` local_betweenness_centrality` due to the performance issues for larger graphs. However, it cannot be normalised by the number of nodes within the whole graph, only by the number of nodes within subgraph. Normalisation by the whole graph can be done manually afterwards if needed.


Patch:
diff --git a/momepy/graph.py b/momepy/graph.py
index 2ecd5de..1c03c04 100644
--- a/momepy/graph.py
+++ b/momepy/graph.py
@@ -934,6 +934,9 @@ def local_betweenness_centrality(
     weight : str, optional
         Use the specified edge attribute as the edge distance in shortest
         path calculations in closeness centrality algorithm
+    normalized : bool, optional
+        If True the betweenness values are normalized by `2/((n-1)(n-2))`,
+        where n is the number of nodes in subgraph.
     **kwargs
         kwargs for ``networkx.betweenness_centrality_subset``
 
@@ -962,8 +965,8 @@ def local_betweenness_centrality(
         sub = nx.ego_graph(
             G, n, radius=radius, distance=distance
         )  # define subgraph of steps=radius
-        netx.nodes[n][name] = nx.betweenness_centrality_subset(
-            G, sub.nodes(), sub.nodes(), weight=weight, normalized=normalized, **kwargs
+        netx.nodes[n][name] = nx.betweenness_centrality(
+            sub, weight=weight, normalized=normalized, **kwargs
         )[n]
 
     return netx


Test patch:
diff --git a/tests/test_graph.py b/tests/test_graph.py
index fe79b81..7e7190f 100644
--- a/tests/test_graph.py
+++ b/tests/test_graph.py
@@ -115,7 +115,7 @@ class TestGraph:
         net2 = mm.local_betweenness_centrality(
             self.network, weight="mm_len", normalized=True
         )
-        check2 = 0.1693121693121693
+        check2 = 0.21333333333333335
         assert (
             net2.nodes[(1603650.450422848, 6464368.600601688)]["betweenness"] == check2
         )