Skip to content

Commit 5c9ac1f

Browse files
authored
Lint and format all files with ruff (#219)
Lint and format
1 parent 28d7c68 commit 5c9ac1f

36 files changed

Lines changed: 1365 additions & 1066 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 *
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 *
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

dataretrieval/codes/__init__.py

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

dataretrieval/nldi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
try:
77
import geopandas as gpd
8-
except ImportError:
9-
raise ImportError("Install geopandas to use the NLDI module.")
8+
except ImportError as err:
9+
raise ImportError("Install geopandas to use the NLDI module.") from err
1010

1111
NLDI_API_BASE_URL = "https://api.water.usgs.gov/nldi/linked-data"
1212
_AVAILABLE_DATA_SOURCES = None
@@ -281,7 +281,7 @@ def get_features(
281281
query_params = {}
282282

283283
if lat:
284-
err_msg = f"Error getting features for lat '{lat}'" f" and long '{long}'"
284+
err_msg = f"Error getting features for lat '{lat}' and long '{long}'"
285285
elif feature_source:
286286
err_msg = (
287287
f"Error getting features for feature source '{feature_source}'"

dataretrieval/nwis.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"The 'nwis' services are deprecated and being decommissioned. "
2727
"Please use the 'waterdata' module to access the new services.",
2828
DeprecationWarning,
29-
stacklevel=2
29+
stacklevel=2,
3030
)
3131

3232
WATERDATA_BASE_URL = "https://nwis.waterdata.usgs.gov/"
@@ -141,7 +141,7 @@ def get_qwdata(
141141
"""
142142
raise NameError(
143143
"`nwis.get_qwdata` has been replaced with `waterdata.get_samples()`."
144-
)
144+
)
145145

146146

147147
def get_discharge_measurements(
@@ -157,7 +157,7 @@ def get_discharge_measurements(
157157
Parameters
158158
----------
159159
sites: string or list of strings, optional, default is None
160-
start: string, optional, default is None
160+
start: string, optional, default is None
161161
Supply date in the format: YYYY-MM-DD
162162
end: string, optional, default is None
163163
Supply date in the format: YYYY-MM-DD
@@ -344,7 +344,7 @@ def get_gwlevels(
344344

345345
if datetime_index is True:
346346
df = format_datetime(df, "lev_dt", "lev_tm", "lev_tz_cd")
347-
347+
348348
# Filter by kwarg parameterCd because the service doesn't do it
349349
if "parameterCd" in kwargs:
350350
pcodes = kwargs["parameterCd"]
@@ -696,7 +696,8 @@ def get_info(ssl_check: bool = True, **kwargs) -> Tuple[pd.DataFrame, BaseMetada
696696
"refer to https://waterdata.usgs.gov.nwis/qwdata and "
697697
"https://doi-usgs.github.io/dataRetrieval/articles/Status.html "
698698
"or email CompTools@usgs.gov."
699-
)
699+
),
700+
stacklevel=2,
700701
)
701702
# convert bool to string if necessary
702703
kwargs["seriesCatalogOutput"] = "True"

dataretrieval/samples.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66

77
from __future__ import annotations
88

9-
from typing import TYPE_CHECKING, Literal, get_args
10-
11-
import pandas as pd
129
import warnings
10+
from typing import TYPE_CHECKING
1311

1412
from dataretrieval.utils import BaseMetadata
1513

1614
if TYPE_CHECKING:
1715
from typing import Optional, Tuple, Union
18-
from dataretrieval.waterdata import SERVICES, PROFILES
16+
1917
from pandas import DataFrame
2018

19+
from dataretrieval.waterdata import PROFILES, SERVICES
20+
21+
2122
def get_usgs_samples(
2223
ssl_check: bool = True,
2324
service: SERVICES = "results",
@@ -111,7 +112,7 @@ def get_usgs_samples(
111112
A user supplied characteristic name describing one or more results.
112113
boundingBox: list of four floats, optional
113114
Filters on the the associated monitoring location's point location
114-
by checking if it is located within the specified geographic area.
115+
by checking if it is located within the specified geographic area.
115116
The logic is inclusive, i.e. it will include locations that overlap
116117
with the edge of the bounding box. Values are separated by commas,
117118
expressed in decimal degrees, NAD83, and longitudes west of Greenwich
@@ -120,7 +121,7 @@ def get_usgs_samples(
120121
- Western-most longitude
121122
- Southern-most latitude
122123
- Eastern-most longitude
123-
- Northern-most longitude
124+
- Northern-most longitude
124125
Example: [-92.8,44.2,-88.9,46.0]
125126
countryFips : string or list of strings, optional
126127
Example: "US" (United States)
@@ -143,7 +144,7 @@ def get_usgs_samples(
143144
usgsPCode : string or list of strings, optional
144145
5-digit number used in the US Geological Survey computerized
145146
data system, National Water Information System (NWIS), to
146-
uniquely identify a specific constituent. Check the
147+
uniquely identify a specific constituent. Check the
147148
`characteristic_lookup()` function in this module for all possible
148149
inputs.
149150
Example: "00060" (Discharge, cubic feet per second)
@@ -173,7 +174,7 @@ def get_usgs_samples(
173174
recordIdentifierUserSupplied : string or list of strings, optional
174175
Internal AQS record identifier that returns 1 entry. Only available
175176
for the "results" service.
176-
177+
177178
Returns
178179
-------
179180
df : ``pandas.DataFrame``
@@ -187,8 +188,8 @@ def get_usgs_samples(
187188
188189
>>> # Get PFAS results within a bounding box
189190
>>> df, md = dataretrieval.samples.get_usgs_samples(
190-
... boundingBox=[-90.2,42.6,-88.7,43.2],
191-
... characteristicGroup="Organics, PFAS"
191+
... boundingBox=[-90.2, 42.6, -88.7, 43.2],
192+
... characteristicGroup="Organics, PFAS",
192193
... )
193194
194195
>>> # Get all activities for the Commonwealth of Virginia over a date range
@@ -197,22 +198,31 @@ def get_usgs_samples(
197198
... profile="sampact",
198199
... activityStartDateLower="2023-10-01",
199200
... activityStartDateUpper="2024-01-01",
200-
... stateFips="US:51")
201+
... stateFips="US:51",
202+
... )
201203
202204
>>> # Get all pH samples for two sites in Utah
203205
>>> df, md = dataretrieval.samples.get_usgs_samples(
204-
... monitoringLocationIdentifier=['USGS-393147111462301', 'USGS-393343111454101'],
205-
... usgsPCode='00400')
206+
... monitoringLocationIdentifier=[
207+
... "USGS-393147111462301",
208+
... "USGS-393343111454101",
209+
... ],
210+
... usgsPCode="00400",
211+
... )
206212
207213
"""
208214

209215
warnings.warn(
210-
"`get_usgs_samples` is deprecated and will be removed. Use `waterdata.get_samples` instead.",
216+
(
217+
"`get_usgs_samples` is deprecated and will be removed. "
218+
"Use `waterdata.get_samples` instead."
219+
),
211220
DeprecationWarning,
212221
stacklevel=2,
213222
)
214223

215224
from dataretrieval.waterdata import get_samples
225+
216226
result = get_samples(
217227
ssl_check=ssl_check,
218228
service=service,
@@ -242,5 +252,3 @@ def get_usgs_samples(
242252
)
243253

244254
return result
245-
246-

dataretrieval/streamstats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,4 @@ def from_streamstats_json(cls, streamstats_json):
158158

159159
def __init__(self, rcode, xlocation, ylocation):
160160
"""Init method that calls the :obj:`from_streamstats_json` method."""
161-
self = get_watershed(rcode, xlocation, ylocation)
161+
get_watershed(rcode, xlocation, ylocation)

dataretrieval/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ def to_str(listlike, delimiter=","):
3939
'0+10+42'
4040
4141
"""
42-
if type(listlike) == list:
42+
if isinstance(listlike, list):
4343
return delimiter.join([str(x) for x in listlike])
4444

45-
elif type(listlike) == pd.core.series.Series:
45+
elif isinstance(listlike, pd.core.series.Series):
4646
return delimiter.join(listlike.tolist())
4747

48-
elif type(listlike) == pd.core.indexes.base.Index:
48+
elif isinstance(listlike, pd.core.indexes.base.Index):
4949
return delimiter.join(listlike.tolist())
5050

51-
elif type(listlike) == str:
51+
elif isinstance(listlike, str):
5252
return listlike
5353

5454

@@ -91,6 +91,7 @@ def format_datetime(df, date_field, time_field, tz_field):
9191
f"Warning: {count} incomplete dates found, "
9292
+ "consider setting datetime_index to False.",
9393
UserWarning,
94+
stacklevel=2,
9495
)
9596

9697
return df
@@ -229,6 +230,5 @@ def __init__(self, url):
229230

230231
def __str__(self):
231232
return (
232-
"No sites/data found using the selection criteria specified in url: "
233-
"{url}"
233+
"No sites/data found using the selection criteria specified in url: {url}"
234234
).format(url=self.url)

0 commit comments

Comments
 (0)