Skip to content

Commit

Permalink
MNT: Remove individual imports of exceptions from the high-level API …
Browse files Browse the repository at this point in the history
…and add exceptions modules instead. [skip ci]
  • Loading branch information
Taher Chegini committed Oct 6, 2024
1 parent 871042f commit abda60d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 39 deletions.
20 changes: 0 additions & 20 deletions src/pynhd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@

from pynhd import exceptions
from pynhd.core import AGRBase, GeoConnex, ScienceBase
from pynhd.exceptions import (
DependencyError,
InputRangeError,
InputTypeError,
InputValueError,
MissingColumnError,
MissingCRSError,
MissingItemError,
NoTerminalError,
ZeroMatchedError,
)
from pynhd.network_tools import (
NHDTools,
enhd_flowlines_nx,
Expand Down Expand Up @@ -51,15 +40,6 @@
__version__ = "999"

__all__ = [
"DependencyError",
"InputRangeError",
"InputValueError",
"InputTypeError",
"MissingItemError",
"MissingColumnError",
"MissingCRSError",
"ZeroMatchedError",
"NoTerminalError",
"prepare_nhdplus",
"topoogical_sort",
"vector_accumulation",
Expand Down
11 changes: 7 additions & 4 deletions src/pynhd/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

from __future__ import annotations

from typing import Generator
from typing import TYPE_CHECKING

import async_retriever as ar
import pygeoogc as ogc
import pygeoutils as pgu
import async_retriever.exceptions as ar
import pygeoogc.exceptions as ogc
import pygeoutils.exceptions as pgu

if TYPE_CHECKING:
from collections.abc import Generator


class ZeroMatchedError(ogc.ZeroMatchedError):
Expand Down
16 changes: 8 additions & 8 deletions src/pynhd/network_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import io
import warnings
from collections.abc import Iterable
from pathlib import Path
from typing import TYPE_CHECKING, Any, Callable, Iterable, Union, cast
from typing import TYPE_CHECKING, Any, Callable, Union, cast

import cytoolz.curried as tlz
import geopandas as gpd
Expand All @@ -20,7 +21,7 @@
import async_retriever as ar
import pygeoutils as pgu
from pygeoogc import streaming_download
from pygeoutils import InputTypeError
from pygeoutils.exceptions import InputTypeError
from pynhd import nhdplus_derived as derived
from pynhd.core import ScienceBase
from pynhd.exceptions import (
Expand Down Expand Up @@ -553,19 +554,19 @@ def _get_idx(d_sp: npt.NDArray[np.float64], distance: float) -> npt.NDArray[np.i


def _get_spline_params(
line: LineString, n_seg: int, distance: float, crs: CRSTYPE, smoothing: float | None
line: LineString, n_seg: int, distance: float, smoothing: float | None
) -> tuple[
npt.NDArray[np.float64],
npt.NDArray[np.float64],
npt.NDArray[np.float64],
]:
"""Get Spline parameters (x, y, phi)."""
_n_seg = n_seg
spline = pgu.spline_linestring(line, crs, _n_seg, smoothing=smoothing)
spline = pgu.spline_linestring(line, _n_seg, smoothing=smoothing)
idx = _get_idx(spline.distance, distance)
while np.isnan(idx).any():
_n_seg *= 2
spline = pgu.spline_linestring(line, crs, _n_seg, smoothing=smoothing)
spline = pgu.spline_linestring(line, _n_seg, smoothing=smoothing)
idx = _get_idx(spline.distance, distance)
x, y, phi = spline.x[idx], spline.y[idx], spline.phi[idx]
spacing = np.diff(spline.distance[idx])
Expand All @@ -587,7 +588,6 @@ def _xs_planar(
n_seg: int,
half_width: float,
distance: float,
crs: CRSTYPE,
smoothing: float | None,
) -> npt.NDArray[LineString]: # pyright: ignore
"""Get cross-sections along a line at a given spacing.
Expand Down Expand Up @@ -621,7 +621,7 @@ def _xs_planar(

if shapely.get_num_points(line) < 4:
line = shapely.segmentize(line, line.length / 4)
x, y, phi = _get_spline_params(line, n_seg, distance, crs, smoothing)
x, y, phi = _get_spline_params(line, n_seg, distance, smoothing)

xy = np.c_[x, y]
# Normal vector of the centerline at each point.
Expand Down Expand Up @@ -794,7 +794,7 @@ def flowline_xsection(

n_segments = (int(np.ceil(ln.length / distance)) * 100 for ln in lines)
main_split = tlz.concat(
_xs_planar(ln, n_seg, half_width, distance, flw.crs, smoothing)
_xs_planar(ln, n_seg, half_width, distance, smoothing)
for ln, n_seg in zip(lines, n_segments)
)

Expand Down
2 changes: 1 addition & 1 deletion src/pynhd/nhdplus_derived.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def epa_nhd_catchments(
*[
(
"https://qed.epa.gov/hms/rest/api/info/catchment",
{"params": {**f_kwd, "comid": comid}},
{"params": f_kwd | {"comid": comid}},
)
for comid in clist
]
Expand Down
20 changes: 14 additions & 6 deletions src/pynhd/pynhd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations

import warnings
from typing import TYPE_CHECKING, Any, Generator, Literal, Sequence, Union, cast, overload
from typing import TYPE_CHECKING, Any, Literal, Union, cast, overload

import cytoolz.curried as tlz
import numpy as np
Expand All @@ -15,12 +15,20 @@
import async_retriever as ar
import pygeoogc as ogc
import pygeoutils as geoutils
from pygeoogc import WFS, InputValueError, ServiceURL
from pygeoutils import EmptyResponseError, InputTypeError
from pygeoogc import WFS, ServiceURL
from pygeoutils.exceptions import EmptyResponseError
from pynhd.core import AGRBase, PyGeoAPIBase, PyGeoAPIBatch
from pynhd.exceptions import InputRangeError, MissingItemError, ZeroMatchedError
from pynhd.exceptions import (
InputRangeError,
InputTypeError,
InputValueError,
MissingItemError,
ZeroMatchedError,
)

if TYPE_CHECKING:
from collections.abc import Generator, Sequence

import geopandas as gpd
import pyproj
from shapely import MultiPoint, MultiPolygon, Point, Polygon
Expand Down Expand Up @@ -907,7 +915,7 @@ def _check_resp(resp: dict[str, Any] | list[dict[str, Any]] | None) -> bool:

@overload
def _get_urls(
self, url_parts: Generator[tuple[str, ...], None, None] | str, raw: Literal[True] = ...
self, url_parts: Generator[tuple[str, ...], None, None] | str, raw: Literal[True] = True
) -> tuple[list[int], list[dict[str, Any]] | dict[str, Any]]: ...

@overload
Expand Down Expand Up @@ -1150,7 +1158,7 @@ def getcharacteristic_byid(
char_type: str,
fsource: str = ...,
char_ids: str | list[str] = ...,
values_only: Literal[True] = ...,
values_only: Literal[True] = True,
) -> pd.DataFrame: ...

@overload
Expand Down

0 comments on commit abda60d

Please sign in to comment.