Skip to content

Commit 33bba33

Browse files
committed
Ruff and fixes
1 parent e9726fe commit 33bba33

20 files changed

Lines changed: 542 additions & 546 deletions

dataretrieval/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
except PackageNotFoundError:
66
__version__ = "version-unknown"
77

8-
from dataretrieval.nadp import * # noqa: F403
9-
from dataretrieval.nwis import * # noqa: F403
10-
from dataretrieval.samples import * # noqa: F403
11-
from dataretrieval.streamstats import * # noqa: F403
12-
from dataretrieval.utils import * # noqa: F403
13-
from dataretrieval.waterdata import * # noqa: F403
14-
from dataretrieval.waterwatch import * # noqa: F403
15-
from dataretrieval.wqp import * # noqa: F403
8+
from dataretrieval.nadp import *
9+
from dataretrieval.nwis import *
10+
from dataretrieval.samples import *
11+
from dataretrieval.streamstats import *
12+
from dataretrieval.utils import *
13+
from dataretrieval.waterdata import *
14+
from dataretrieval.waterwatch import *
15+
from dataretrieval.wqp import *

dataretrieval/codes/__init__.py

100755100644
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from .states import * # noqa: F403
2-
from .timezones import * # noqa: F403
1+
from .states import *
2+
from .timezones import *

dataretrieval/nldi.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from __future__ import annotations
2+
13
from json import JSONDecodeError
2-
from typing import Literal, Optional, Union
4+
from typing import Literal
35

46
from dataretrieval.utils import query
57

@@ -32,13 +34,13 @@ def _query_nldi(url, query_params, error_message):
3234
def get_flowlines(
3335
navigation_mode: str,
3436
distance: int = 5,
35-
feature_source: Optional[str] = None,
36-
feature_id: Optional[str] = None,
37-
comid: Optional[int] = None,
38-
stop_comid: Optional[int] = None,
37+
feature_source: str | None = None,
38+
feature_id: str | None = None,
39+
comid: int | None = None,
40+
stop_comid: int | None = None,
3941
trim_start: bool = False,
4042
as_json: bool = False,
41-
) -> Union[gpd.GeoDataFrame, dict]:
43+
) -> gpd.GeoDataFrame | dict:
4244
"""Gets the flowlines for the specified navigation either by comid or feature
4345
source in WGS84 lat/long coordinates as GeoDataFrame containing a polyline geometry.
4446
@@ -116,7 +118,7 @@ def get_basin(
116118
simplified: bool = True,
117119
split_catchment: bool = False,
118120
as_json: bool = False,
119-
) -> Union[gpd.GeoDataFrame, dict]:
121+
) -> gpd.GeoDataFrame | dict:
120122
"""Gets the aggregated basin for the specified feature in WGS84 lat/lon
121123
as GeoDataFrame or as JSON conatining a polygon geometry.
122124
@@ -164,17 +166,17 @@ def get_basin(
164166

165167

166168
def get_features(
167-
data_source: Optional[str] = None,
168-
navigation_mode: Optional[str] = None,
169+
data_source: str | None = None,
170+
navigation_mode: str | None = None,
169171
distance: int = 50,
170-
feature_source: Optional[str] = None,
171-
feature_id: Optional[str] = None,
172-
comid: Optional[int] = None,
173-
lat: Optional[float] = None,
174-
long: Optional[float] = None,
175-
stop_comid: Optional[int] = None,
172+
feature_source: str | None = None,
173+
feature_id: str | None = None,
174+
comid: int | None = None,
175+
lat: float | None = None,
176+
long: float | None = None,
177+
stop_comid: int | None = None,
176178
as_json: bool = False,
177-
) -> Union[gpd.GeoDataFrame, dict]:
179+
) -> gpd.GeoDataFrame | dict:
178180
"""Gets all features found along the specified navigation either by
179181
comid or feature source as points in WGS84 lat/long coordinates - a GeoDataFrame
180182
containing a point geometry.
@@ -247,11 +249,10 @@ def get_features(
247249
)
248250

249251
if not lat:
250-
if comid or data_source:
251-
if navigation_mode is None:
252-
raise ValueError(
253-
"navigation_mode is required if comid or data_source is provided"
254-
)
252+
if (comid or data_source) and navigation_mode is None:
253+
raise ValueError(
254+
"navigation_mode is required if comid or data_source is provided"
255+
)
255256
# validate the feature source and comid
256257
_validate_feature_source_comid(feature_source, feature_id, comid)
257258
# validate the data source
@@ -334,14 +335,14 @@ def get_features_by_data_source(data_source: str) -> gpd.GeoDataFrame:
334335

335336

336337
def search(
337-
feature_source: Optional[str] = None,
338-
feature_id: Optional[str] = None,
339-
navigation_mode: Optional[str] = None,
340-
data_source: Optional[str] = None,
338+
feature_source: str | None = None,
339+
feature_id: str | None = None,
340+
navigation_mode: str | None = None,
341+
data_source: str | None = None,
341342
find: Literal["basin", "flowlines", "features"] = "features",
342-
comid: Optional[int] = None,
343-
lat: Optional[float] = None,
344-
long: Optional[float] = None,
343+
comid: int | None = None,
344+
lat: float | None = None,
345+
long: float | None = None,
345346
distance: int = 50,
346347
) -> dict:
347348
"""Searches for the specified feature in NLDI and returns the results
@@ -489,7 +490,7 @@ def _validate_navigation_mode(navigation_mode: str):
489490

490491

491492
def _validate_feature_source_comid(
492-
feature_source: Optional[str], feature_id: Optional[str], comid: Optional[int]
493+
feature_source: str | None, feature_id: str | None, comid: int | None
493494
):
494495
if feature_source is not None and feature_id is None:
495496
raise ValueError("feature_id is required if feature_source is provided")

0 commit comments

Comments
 (0)