From dc71596fc224d699b4bff41a4c546eac44beb3d1 Mon Sep 17 00:00:00 2001 From: nialov Date: Fri, 1 Nov 2024 11:51:46 +0200 Subject: [PATCH] fix: force return types Some returns are flaky on different platforms on what Python or numpy type they exactly return. --- fractopo/fractopo_utils.py | 7 +++++-- fractopo/general.py | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/fractopo/fractopo_utils.py b/fractopo/fractopo_utils.py index 6c27714..d58942e 100644 --- a/fractopo/fractopo_utils.py +++ b/fractopo/fractopo_utils.py @@ -144,8 +144,11 @@ def conditional_linemerge_collection( for i, trace in enumerate(traces.geometry): assert isinstance(trace, LineString) trace_candidates_idx: List[int] = list( - spatial_index.intersection( - geom_bounds(safe_buffer(trace, buffer_value * 2)) + map( + int, + spatial_index.intersection( + geom_bounds(safe_buffer(trace, buffer_value * 2)) + ), ) ) trace_candidates_idx.remove(i) diff --git a/fractopo/general.py b/fractopo/general.py index c8c2a8a..9d8d1b3 100644 --- a/fractopo/general.py +++ b/fractopo/general.py @@ -416,7 +416,7 @@ def determine_regression_azimuth(line: LineString) -> float: if azimuth < 0: azimuth = 90 - np.rad2deg(np.arctan(coef)) # type: ignore assert isinstance(azimuth, float) and 0 <= azimuth <= 180 - return azimuth + return float(azimuth) def determine_azimuth(line: LineString, halved: bool) -> float: @@ -1499,20 +1499,20 @@ def total_bounds( """ Get total bounds of geodataset. - >>> geodata = gpd.GeoSeries([Point(-10, 10), Point(10, 10)]) + >>> geodata = gpd.GeoSeries([Point(-10, 10), Point(10, 10)]) >>> total_bounds(geodata) (-10.0, 10.0, 10.0, 10.0) """ if geodata.empty or all( geom is None or geom.is_empty for geom in geodata.geometry.values ): - return tuple([np.nan] * 4) + return (np.nan, np.nan, np.nan, np.nan) bounds = geodata.total_bounds if not len(bounds) == 4: raise ValueError( f"Expected total_bounds to return an array of length 4: {bounds}." ) - return bounds[0], bounds[1], bounds[2], bounds[3] + return float(bounds[0]), float(bounds[1]), float(bounds[2]), float(bounds[3]) def read_geofile(path: Path) -> gpd.GeoDataFrame: