Skip to content

Commit

Permalink
COMPAT: numpy 2.0 compatibility (#596)
Browse files Browse the repository at this point in the history
* COMPAT: numpy 2.0 compatibility

* get also pandas nightly

* force upgrade

* stop running CI if there's another commit to PR

* --upgrade

* --force-reinstall

* use pip for most

* one more

* -np.inf

* ignore index names
  • Loading branch information
martinfleis committed Jun 12, 2024
1 parent 6df41c3 commit d27ece9
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 50 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
20 changes: 8 additions & 12 deletions ci/envs/312-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +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 --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
- git+https://github.com/pysal/inequality.git
- osmnx
- scikit-learn
36 changes: 18 additions & 18 deletions momepy/functional/_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions momepy/functional/_diversity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 12 additions & 12 deletions momepy/functional/_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions momepy/functional/tests/test_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions momepy/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
):
Expand Down

0 comments on commit d27ece9

Please sign in to comment.