From a2a0ac613c00724ec0855ee91117821457ce2628 Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Wed, 12 Jun 2024 15:54:03 +0200 Subject: [PATCH 01/10] COMPAT: numpy 2.0 compatibility --- ci/envs/312-dev.yaml | 2 ++ momepy/functional/_dimension.py | 36 ++++++++++++++++----------------- momepy/functional/_diversity.py | 8 ++++---- momepy/functional/_shape.py | 24 +++++++++++----------- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/ci/envs/312-dev.yaml b/ci/envs/312-dev.yaml index a8e29321..f10c5fd7 100644 --- a/ci/envs/312-dev.yaml +++ b/ci/envs/312-dev.yaml @@ -22,6 +22,8 @@ dependencies: - scikit-learn - pip - pip: + - --pre --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --extra-index-url https://pypi.org/simple + - numpy - git+https://github.com/geopandas/geopandas.git - git+https://github.com/pysal/libpysal.git - git+https://github.com/networkx/networkx.git diff --git a/momepy/functional/_dimension.py b/momepy/functional/_dimension.py index ff05cc39..987ea405 100644 --- a/momepy/functional/_dimension.py +++ b/momepy/functional/_dimension.py @@ -28,9 +28,9 @@ def volume( - area: NDArray[np.float_] | Series, - height: NDArray[np.float_] | Series, -) -> NDArray[np.float_] | Series: + area: NDArray[np.float64] | Series, + height: NDArray[np.float64] | Series, +) -> NDArray[np.float64] | Series: """ Calculates volume of each object in given GeoDataFrame based on its height and area. @@ -39,24 +39,24 @@ def volume( Parameters ---------- - area : NDArray[np.float_] | Series + area : NDArray[np.float64] | Series array of areas - height : NDArray[np.float_] | Series + height : NDArray[np.float64] | Series array of heights Returns ------- - NDArray[np.float_] | Series + NDArray[np.float64] | Series array of a type depending on the input """ return area * height def floor_area( - area: NDArray[np.float_] | Series, - height: NDArray[np.float_] | Series, - floor_height: float | NDArray[np.float_] | Series = 3, -) -> NDArray[np.float_] | Series: + area: NDArray[np.float64] | Series, + height: NDArray[np.float64] | Series, + floor_height: float | NDArray[np.float64] | Series = 3, +) -> NDArray[np.float64] | Series: """Calculates floor area of each object based on height and area. The number of @@ -69,17 +69,17 @@ def floor_area( Parameters ---------- - area : NDArray[np.float_] | Series + area : NDArray[np.float64] | Series array of areas - height : NDArray[np.float_] | Series + height : NDArray[np.float64] | Series array of heights - floor_height : float | NDArray[np.float_] | Series, optional + floor_height : float | NDArray[np.float64] | Series, optional float denoting the uniform floor height or an aarray reflecting the building height by geometry, by default 3 Returns ------- - NDArray[np.float_] | Series + NDArray[np.float64] | Series array of a type depending on the input """ return area * (height // floor_height) @@ -172,7 +172,7 @@ def perimeter_wall( def weighted_character( - y: NDArray[np.float_] | Series, area: NDArray[np.float_] | Series, graph: Graph + y: NDArray[np.float64] | Series, area: NDArray[np.float64] | Series, graph: Graph ) -> Series: """Calculates the weighted character. @@ -191,9 +191,9 @@ def weighted_character( Parameters ---------- - y : NDArray[np.float_] | Series + y : NDArray[np.float64] | Series The character values to be weighted. - area : NDArray[np.float_] | Series + area : NDArray[np.float64] | Series The area values to be used as weightss graph : libpysal.graph.Graph A spatial weights matrix for values and areas. @@ -392,7 +392,7 @@ def _get_point_njit(x1, y1, bearing, dist): @njit def generate_ticks(list_points, end_markers, tick_length): - ticks = np.empty((len(list_points) * 2, 4), dtype=np.float64) + ticks = np.empty((len(list_points) * 2, 4), dtype=float) for i in range(len(list_points)): tick_pos = i * 2 diff --git a/momepy/functional/_diversity.py b/momepy/functional/_diversity.py index 3ff5ea37..ad2c1880 100644 --- a/momepy/functional/_diversity.py +++ b/momepy/functional/_diversity.py @@ -79,8 +79,8 @@ def _percentile_limited_group_grouper(y, group_index, q=(25, 75)): def describe_agg( - y: NDArray[np.float_] | Series, - aggregation_key: NDArray[np.float_] | Series, + y: NDArray[np.float64] | Series, + aggregation_key: NDArray[np.float64] | Series, result_index: pd.Index = None, q: tuple[float, float] | list[float] | None = None, statistics: list[str] | None = None, @@ -171,8 +171,8 @@ def describe_agg( def describe_reached_agg( - y: NDArray[np.float_] | Series, - graph_index: NDArray[np.float_] | Series, + y: NDArray[np.float64] | Series, + graph_index: NDArray[np.float64] | Series, graph: Graph, q: tuple[float, float] | list[float] | None = None, statistics: list[str] | None = None, diff --git a/momepy/functional/_shape.py b/momepy/functional/_shape.py index 15eb5481..0d0a970e 100644 --- a/momepy/functional/_shape.py +++ b/momepy/functional/_shape.py @@ -32,7 +32,7 @@ def form_factor( geometry: GeoDataFrame | GeoSeries, - height: NDArray[np.float_] | Series, + height: NDArray[np.float64] | Series, ) -> Series: """Calculates the form factor of each object given its geometry and height. @@ -50,7 +50,7 @@ def form_factor( ---------- geometry : GeoDataFrame | GeoSeries A GeoDataFrame or GeoSeries containing polygons to analyse. - height : NDArray[np.float_] | Series + height : NDArray[np.float64] | Series array of heights Returns @@ -178,7 +178,7 @@ def convexity(geometry: GeoDataFrame | GeoSeries) -> Series: def courtyard_index( geometry: GeoDataFrame | GeoSeries, - courtyard_area: NDArray[np.float_] | Series | None = None, + courtyard_area: NDArray[np.float64] | Series | None = None, ) -> Series: """Calculates the courtyard index of each object given its geometry. @@ -191,7 +191,7 @@ def courtyard_index( ---------- geometry : GeoDataFrame | GeoSeries A GeoDataFrame or GeoSeries containing polygons to analyse. - courtyard_area : NDArray[np.float_] | Series | None, optional + courtyard_area : NDArray[np.float64] | Series | None, optional array of courtyard areas. If None, it will be calculated, by default None Returns @@ -227,7 +227,7 @@ def rectangularity(geometry: GeoDataFrame | GeoSeries) -> Series: def shape_index( geometry: GeoDataFrame | GeoSeries, - longest_axis_length: NDArray[np.float_] | Series | None = None, + longest_axis_length: NDArray[np.float64] | Series | None = None, ) -> Series: """Calculates the shape index of each object given its geometry. @@ -238,7 +238,7 @@ def shape_index( ---------- geometry : GeoDataFrame | GeoSeries A GeoDataFrame or GeoSeries containing polygons to analyse. - longest_axis_length : NDArray[np.float_] | Series | None, optional + longest_axis_length : NDArray[np.float64] | Series | None, optional array of longest axis lengths. If None, it will be calculated, by default None Returns @@ -475,7 +475,7 @@ def linearity(geometry: GeoDataFrame | GeoSeries) -> Series: def compactness_weighted_axis( geometry: GeoDataFrame | GeoSeries, - longest_axis_length: NDArray[np.float_] | Series | None = None, + longest_axis_length: NDArray[np.float64] | Series | None = None, ) -> Series: """Calculates the compactness-weighted axis of each object in a given GeoDataFrame. @@ -487,7 +487,7 @@ def compactness_weighted_axis( ---------- geometry : GeoDataFrame | GeoSeries A GeoDataFrame or GeoSeries containing polygons to analyse. - longest_axis_length : NDArray[np.float_] | Series | None, optional + longest_axis_length : NDArray[np.float64] | Series | None, optional array of longest axis lengths. If None, it will be calculated, by default None Returns @@ -506,13 +506,13 @@ def compactness_weighted_axis( def _true_angles_mask( - points: NDArray[np.float_], eps: float, return_degrees: bool = False -) -> NDArray[np.bool_] | tuple[NDArray[np.bool_], NDArray[np.float_]]: + points: NDArray[np.float64], eps: float, return_degrees: bool = False +) -> NDArray[np.bool_] | tuple[NDArray[np.bool_], NDArray[np.float64]]: """Calculates the mask of true angles. Parameters ---------- - points : NDArray[np.float_] + points : NDArray[np.float64] array of points eps : float Deviation from 180 degrees to consider a corner @@ -521,7 +521,7 @@ def _true_angles_mask( Returns ------- - NDArray[np.bool_] | tuple[NDArray[np.bool_], NDArray[np.float_]] + NDArray[np.bool_] | tuple[NDArray[np.bool_], NDArray[np.float64]] boolean array or a tuple of boolean array and float array of degrees """ a = np.roll(points, 1, axis=0) From 91b6d720775dcf499f0bc46895c4f58587de34ba Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Wed, 12 Jun 2024 15:55:24 +0200 Subject: [PATCH 02/10] get also pandas nightly --- ci/envs/312-dev.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/envs/312-dev.yaml b/ci/envs/312-dev.yaml index f10c5fd7..266124c3 100644 --- a/ci/envs/312-dev.yaml +++ b/ci/envs/312-dev.yaml @@ -24,6 +24,7 @@ dependencies: - pip: - --pre --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --extra-index-url https://pypi.org/simple - numpy + - pandas - git+https://github.com/geopandas/geopandas.git - git+https://github.com/pysal/libpysal.git - git+https://github.com/networkx/networkx.git From 374b7d7d0925023f470ec7bb22e8308a09f3968c Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Wed, 12 Jun 2024 15:59:10 +0200 Subject: [PATCH 03/10] force upgrade --- ci/envs/312-dev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/envs/312-dev.yaml b/ci/envs/312-dev.yaml index 266124c3..17af4d82 100644 --- a/ci/envs/312-dev.yaml +++ b/ci/envs/312-dev.yaml @@ -22,7 +22,7 @@ dependencies: - scikit-learn - pip - pip: - - --pre --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --extra-index-url https://pypi.org/simple + - --pre --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --extra-index-url https://pypi.org/simple -U - numpy - pandas - git+https://github.com/geopandas/geopandas.git From f61da1ef29e524bd8366cad7396c8eff1e02abaf Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Wed, 12 Jun 2024 16:01:46 +0200 Subject: [PATCH 04/10] stop running CI if there's another commit to PR --- .github/workflows/tests.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f3187e26..8fa77196 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -15,6 +15,10 @@ on: default: test required: false +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: Test: name: ${{ matrix.os }}, ${{ matrix.environment-file }} From ae7a7444f87b37a483e17518aee7d2621378cde7 Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Wed, 12 Jun 2024 16:03:06 +0200 Subject: [PATCH 05/10] --upgrade --- ci/envs/312-dev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/envs/312-dev.yaml b/ci/envs/312-dev.yaml index 17af4d82..baafd89b 100644 --- a/ci/envs/312-dev.yaml +++ b/ci/envs/312-dev.yaml @@ -22,7 +22,7 @@ dependencies: - scikit-learn - pip - pip: - - --pre --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --extra-index-url https://pypi.org/simple -U + - --pre --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --extra-index-url https://pypi.org/simple --upgrade - numpy - pandas - git+https://github.com/geopandas/geopandas.git From 2862db7ee95fa0f4a386ce785b5ef78f20e4d751 Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Wed, 12 Jun 2024 16:05:19 +0200 Subject: [PATCH 06/10] --force-reinstall --- ci/envs/312-dev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/envs/312-dev.yaml b/ci/envs/312-dev.yaml index baafd89b..3bd03133 100644 --- a/ci/envs/312-dev.yaml +++ b/ci/envs/312-dev.yaml @@ -22,7 +22,7 @@ dependencies: - scikit-learn - pip - pip: - - --pre --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --extra-index-url https://pypi.org/simple --upgrade + - --pre --force-reinstall --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --extra-index-url https://pypi.org/simple - numpy - pandas - git+https://github.com/geopandas/geopandas.git From 21687e1edaf6e451c1c07a56ed8c7c685883caca Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Wed, 12 Jun 2024 16:10:43 +0200 Subject: [PATCH 07/10] use pip for most --- ci/envs/312-dev.yaml | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/ci/envs/312-dev.yaml b/ci/envs/312-dev.yaml index 3bd03133..ad776af8 100644 --- a/ci/envs/312-dev.yaml +++ b/ci/envs/312-dev.yaml @@ -3,31 +3,24 @@ channels: - conda-forge dependencies: - python=3.12 - - dask - - geopandas - inequality - - libpysal>=4.11.0 - - networkx - - osmnx - packaging - - pandas!=1.5.0 - - shapely>=2 - tqdm - - numba + # - numba # testing - codecov - pytest - pytest-cov - # for mapclassify - - scikit-learn - pip - pip: - - --pre --force-reinstall --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --extra-index-url https://pypi.org/simple + - --pre --index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple --extra-index-url https://pypi.org/simple - numpy - pandas + - shapely - git+https://github.com/geopandas/geopandas.git - git+https://github.com/pysal/libpysal.git - git+https://github.com/networkx/networkx.git - - git+https://github.com/shapely/shapely.git - git+https://github.com/pysal/mapclassify.git - git+https://github.com/pysal/esda.git + - osmnx + - scikit-learn From 1071461cdc479f00ff7d56d84734ef658775feb4 Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Wed, 12 Jun 2024 16:13:45 +0200 Subject: [PATCH 08/10] one more --- ci/envs/312-dev.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/envs/312-dev.yaml b/ci/envs/312-dev.yaml index ad776af8..119adf74 100644 --- a/ci/envs/312-dev.yaml +++ b/ci/envs/312-dev.yaml @@ -3,7 +3,6 @@ channels: - conda-forge dependencies: - python=3.12 - - inequality - packaging - tqdm # - numba @@ -22,5 +21,6 @@ dependencies: - git+https://github.com/networkx/networkx.git - git+https://github.com/pysal/mapclassify.git - git+https://github.com/pysal/esda.git + - git+https://github.com/pysal/inequality.git - osmnx - scikit-learn From 98353b15107456779b364609986495fc699e0019 Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Wed, 12 Jun 2024 16:16:40 +0200 Subject: [PATCH 09/10] -np.inf --- momepy/preprocessing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/momepy/preprocessing.py b/momepy/preprocessing.py index 9c5e4924..b5faa612 100644 --- a/momepy/preprocessing.py +++ b/momepy/preprocessing.py @@ -1518,7 +1518,7 @@ class FaceArtifacts: ['circlular_compactness', 'isoperimetric_quotient', 'diameter_ratio'], by default "circular_compactness" height_mins : float, optional - Required depth of valleys, by default np.NINF + Required depth of valleys, by default -np.inf height_maxs : float, optional Required height of peaks, by default 0.008 prominence : float, optional @@ -1560,7 +1560,7 @@ def __init__( self, gdf, index="circular_compactness", - height_mins=np.NINF, + height_mins=-np.inf, height_maxs=0.008, prominence=0.00075, ): From 3809064eb3c92a945a315fa62dd62ad6d25a6c9c Mon Sep 17 00:00:00 2001 From: Martin Fleischmann Date: Wed, 12 Jun 2024 16:23:17 +0200 Subject: [PATCH 10/10] ignore index names --- momepy/functional/tests/test_distribution.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/momepy/functional/tests/test_distribution.py b/momepy/functional/tests/test_distribution.py index f0a990a7..4c141a13 100644 --- a/momepy/functional/tests/test_distribution.py +++ b/momepy/functional/tests/test_distribution.py @@ -56,7 +56,7 @@ def test_alignment(self): "max": 21.32311946014944, } r = mm.alignment(orientation, self.graph) - assert_result(r, expected, self.df_buildings) + assert_result(r, expected, self.df_buildings, check_names=False) def test_neighbor_distance(self): expected = { @@ -66,7 +66,7 @@ def test_neighbor_distance(self): "max": 42.164831456311475, } r = mm.neighbor_distance(self.df_buildings, self.graph) - assert_result(r, expected, self.df_buildings) + assert_result(r, expected, self.df_buildings, check_names=False) def test_mean_interbuilding_distance(self): expected = {