Skip to content

Commit

Permalink
MNT: Address issues raised by pyright. [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Taher Chegini committed Jul 7, 2024
1 parent b23cca9 commit 8d94c75
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/pynhd/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def check_coords(
) -> list[tuple[float, float]]:
"""Check the coordinates."""
try:
mps = MultiPoint(coords)
mps = MultiPoint(coords) # pyright: ignore[reportArgumentType]
except (TypeError, AttributeError):
try:
mps = MultiPoint([coords])
Expand Down Expand Up @@ -784,7 +784,7 @@ def bygeometry(
if predicate.upper() not in valid_predicates:
raise InputValueError("predicate", valid_predicates)

geom1 = geoutils.geo2polygon(geometry1, crs, 4326)
geom1 = geoutils.geo2polygon(geometry1, crs, 4326) # pyright: ignore[reportArgumentType]
if not geom1.intersects(shapely_box(*self.item_extent)):
raise InputRangeError("geometry", f"within {self.item_extent}")
try:
Expand All @@ -800,7 +800,7 @@ def bygeometry(
}
)

geom2 = geoutils.geo2polygon(geometry2, crs, 4326)
geom2 = geoutils.geo2polygon(geometry2, crs, 4326) # pyright: ignore[reportArgumentType]
if not geom2.intersects(shapely_box(*self.item_extent)):
raise InputRangeError("geometry", f"within {self.item_extent}")
try:
Expand Down
7 changes: 5 additions & 2 deletions src/pynhd/network_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ def vector_accumulation(
),
label_attribute="str_id",
)
graph = cast("nx.DiGraph", graph)

m_int2str = nx.get_node_attributes(graph, "str_id")
m_str2int = {v: k for k, v in m_int2str.items()}
Expand Down Expand Up @@ -588,7 +589,7 @@ def _xs_planar(
distance: float,
crs: CRSTYPE,
smoothing: float | None,
) -> npt.NDArray[LineString]:
) -> npt.NDArray[LineString]: # pyright: ignore
"""Get cross-sections along a line at a given spacing.
Parameters
Expand Down Expand Up @@ -628,7 +629,7 @@ def _xs_planar(
vn_left = np.c_[-np.sin(phi), np.cos(phi)]

_lines = zip(xy + half_width * vn_left, xy + half_width * vn_right)
return shapely.linestrings(list(_lines))
return shapely.linestrings(list(_lines)) # pyright: ignore[reportReturnType]


def __check_flw(flw: gpd.GeoDataFrame, req_cols: list[str]) -> None:
Expand Down Expand Up @@ -892,6 +893,7 @@ def enhd_flowlines_nx() -> tuple[nx.DiGraph, dict[int, int], list[int]]:
),
label_attribute="str_id",
)
graph = cast("nx.DiGraph", graph)

label2comid = nx.get_node_attributes(graph, "str_id")
s_map = {label2comid[i]: r for i, r in zip(nx.topological_sort(graph), range(len(graph)))}
Expand Down Expand Up @@ -948,6 +950,7 @@ def mainstem_huc12_nx() -> tuple[nx.DiGraph, dict[int, str], list[str]]:
),
label_attribute="str_id",
)
graph = cast("nx.DiGraph", graph)

label2huc = nx.get_node_attributes(graph, "str_id")
s_map = {label2huc[i]: r for i, r in zip(nx.topological_sort(graph), range(len(graph)))}
Expand Down
2 changes: 1 addition & 1 deletion src/pynhd/pynhd.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def elevation_profile(
"""
if not isinstance(line, (LineString, MultiLineString)):
raise InputTypeError("line", "LineString or MultiLineString")
line = geoutils.geometry_reproject(line, crs, 4326)
line = geoutils.geometry_reproject(line, crs, 4326) # pyright: ignore[reportArgumentType]
if isinstance(line, LineString):
coords = line.coords
else:
Expand Down

0 comments on commit 8d94c75

Please sign in to comment.