Skip to content

Commit

Permalink
fix: force return types
Browse files Browse the repository at this point in the history
Some returns are flaky on different platforms on
what Python or numpy type they exactly return.
  • Loading branch information
nialov committed Nov 1, 2024
1 parent 1d78809 commit dc71596
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 5 additions & 2 deletions fractopo/fractopo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions fractopo/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit dc71596

Please sign in to comment.