Skip to content

Commit fb5a79a

Browse files
thodson-usgsclaude
andcommitted
docs: copy-edit docstrings/comments and fix doc/code accuracy gaps
A review pass over the package's docstrings and inline comments for spelling, grammar, clarity, and accuracy against the implementation. Spelling & grammar: - Typos ("Times series" -> "Time series", "datetme", "conatining", "indeces" -> "indices", "ESPSG" -> "EPSG", "NDAP" -> "NADP") plus articles, subject-verb agreement, duplicated words, and punctuation. codespell-clean ("gage" is the intentional USGS spelling). R-language cruft -> Python: - bbox `c(xmin,ymin,xmax,ymax)` -> `[xmin, ymin, xmax, ymax]`; "(numeric) vector"/"a vector of requested columns" -> list wording; `limit : numeric` -> `int`; `thresholds : numeric` -> `number`. Accuracy (docs that disagreed with the code): - Broken `Returns` cross-references to a nonexistent `dataretrieval.utils.Metadata` -> the real classes (`nwis.NWIS_Metadata`, `wqp.WQP_Metadata`, `utils.BaseMetadata`). - get_monitoring_locations: three params typed `float` -> string/iterable. - nwis.query_waterdata / query_waterservices: `service` examples listed values the functions reject -> the accepted sets; removed a duplicated `ssl_check` block and a `bBox` documented as a HUC. - waterdata/utils: _switch_properties_id docstring described a dict (copied from _switch_arg_id); _handle_stats_nesting / _combine_chunk_frames notes corrected to match the code. - get_time_series_metadata: replaced the stale `properties` list (copied from get_daily) with the collection's real queryables. - Added missing pieces: `nadp` module deprecation note; `Raises` on `utils.query` and `streamstats.get_watershed` (plus its `format` param and dual return type); `get_channel` params; `get_stats_por` / `get_stats_date_range` `Returns` sections. - Dropped bogus `Returns` blocks from `__init__` methods (they return None). Code fixes surfaced by the review: - Removed the non-functional `time` parameter from `get_monitoring_locations` and `get_time_series_metadata`. Their OGC collections have no `time` queryable (verified via the collections' queryables and a live 400), so `time=...` only produced an opaque server error; with no `**kwargs`, removal now yields a clear `TypeError`. The observation getters' `time` is valid and untouched. - Fixed a malformed URL in the nwis seriesCatalogOutput deprecation warning (`waterdata.usgs.gov.nwis/qwdata` -> `waterdata.usgs.gov/nwis/qwdata`). ruff check + ruff format clean; mypy --strict clean; tests pass; live-API behavior verified. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent eddcffc commit fb5a79a

13 files changed

Lines changed: 289 additions & 218 deletions

File tree

dataretrieval/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
df, meta = nwis.get_dv(sites="05427718")
1212
1313
Available service modules: ``waterdata``, ``wqp`` (Water Quality Portal),
14-
``nldi``, ``samples``, ``streamstats``, ``nadp``, and the deprecated ``nwis``.
14+
``nldi``, ``samples``, ``streamstats``, and the deprecated ``nwis`` and
15+
``nadp``.
1516
1617
``nldi`` requires geopandas (``pip install dataretrieval[nldi]``) and is
1718
imported on demand: ``from dataretrieval import nldi``.

dataretrieval/codes/states.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
"""List of 2-digit state codes with commented full names."""
1+
"""State code lookups keyed by full state name.
2+
3+
``state_codes`` maps each state name to its two-letter postal abbreviation
4+
(e.g. ``"Alabama": "al"``); ``fips_codes`` maps it to its two-digit FIPS
5+
code (e.g. ``"Alabama": "01"``).
6+
"""
27

38
state_codes = {
49
"Alabama": "al",

dataretrieval/nadp.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
"""
22
Tools for retrieving data from the National Atmospheric Deposition Program
3-
(NADP) including the National Trends Network (NTN), the Mercury Deposition
4-
Network (MDN).
3+
(NADP), including the National Trends Network (NTN) and the Mercury
4+
Deposition Network (MDN).
5+
6+
.. deprecated::
7+
8+
The ``nadp`` module is deprecated and will be removed from
9+
``dataretrieval`` on or after 2026-11-01. NADP is not a USGS data
10+
source; please retrieve NADP data directly from
11+
https://nadp.slh.wisc.edu/.
512
613
National Trends Network
714
-----------------------
8-
The NTN provides long-term records of precipitation chemistry across the
15+
The NTN provides long-term records of precipitation chemistry across the
916
United States. See https://nadp.slh.wisc.edu/ntn for more info.
1017
1118
Mercury Deposition Network
@@ -89,7 +96,7 @@ def tif(self) -> bytes:
8996

9097

9198
def get_annual_MDN_map(measurement_type: str, year: str, path: str) -> str:
92-
"""Download a MDN map from NDAP.
99+
"""Download an MDN map from NADP.
93100
94101
This function looks for a zip file containing gridded information at:
95102
https://nadp.slh.wisc.edu/maps-data/mdn-gradient-maps/.
@@ -143,7 +150,7 @@ def get_annual_NTN_map(
143150
year: str | None = None,
144151
path: str = ".",
145152
) -> str:
146-
"""Download a NTN map from NDAP.
153+
"""Download an NTN map from NADP.
147154
148155
This function looks for a zip file containing gridded information at:
149156
https://nadp.slh.wisc.edu/maps-data/ntn-gradient-maps/.
@@ -158,11 +165,11 @@ def get_annual_NTN_map(
158165
159166
Parameters
160167
----------
161-
measurement : string
162-
The measured constituent to return.
163168
measurement_type : string
164169
The type of measurement, 'conc', 'dep', or 'Precip', which represent
165170
concentration, deposition, or precipitation respectively.
171+
measurement : string
172+
The measured constituent to return.
166173
year : string
167174
Year as a string 'YYYY'
168175
path : string

dataretrieval/nldi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ def get_basin(
135135
as_json: bool = False,
136136
) -> gpd.GeoDataFrame | dict[str, Any]:
137137
"""Gets the aggregated basin for the specified feature in WGS84 lat/lon
138-
as GeoDataFrame or as JSON conatining a polygon geometry.
138+
as GeoDataFrame or as JSON containing a polygon geometry.
139139
140140
Parameters
141141
----------
142142
feature_source: string, name of the feature source
143143
feature_id: string, identifier of the feature
144144
simplified: bool, simplified, default is True
145145
split_catchment: bool, split catchment, default is False
146-
as_json: bool, return basin as JSON is set to True, otherwise return
146+
as_json: bool, return basin as JSON if set to True, otherwise return
147147
as GeoDataFrame, default is False
148148
149149
Returns
@@ -299,8 +299,8 @@ def get_features(
299299
return gdf
300300

301301

302-
# TODO: This function can cause timeout error for some data sources
303-
# - may be we shouldn't provide this function?
302+
# TODO: This function can cause a timeout error for some data sources
303+
# - maybe we shouldn't provide this function?
304304
def get_features_by_data_source(data_source: str) -> gpd.GeoDataFrame:
305305
"""Gets all features found for the specified data source as
306306
points in WGS84 lat/long coordinates as GeoDataFrame containing a point geometry.

dataretrieval/nwis.py

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ def get_discharge_peaks(
251251
Returns
252252
-------
253253
df: ``pandas.DataFrame``
254-
Times series data from the NWIS JSON
255-
md: :obj:`dataretrieval.utils.Metadata`
254+
Time series data from the NWIS JSON
255+
md: :obj:`dataretrieval.nwis.NWIS_Metadata`
256256
A custom metadata object
257257
258258
Examples
@@ -331,7 +331,7 @@ def get_stats(
331331
-------
332332
df: ``pandas.DataFrame``
333333
Statistics data from the statistics service
334-
md: :obj:`dataretrieval.utils.Metadata`
334+
md: :obj:`dataretrieval.nwis.NWIS_Metadata`
335335
A custom metadata object
336336
337337
.. todo::
@@ -372,7 +372,7 @@ def query_waterdata(
372372
Parameters
373373
----------
374374
service: string
375-
Name of the service to query: 'site', 'stats', etc.
375+
Name of the service to query: 'peaks' or 'ratings'.
376376
ssl_check: bool, optional
377377
If True, check SSL certificates, if False, do not check SSL,
378378
default is True
@@ -424,10 +424,7 @@ def query_waterservices(
424424
Parameters
425425
----------
426426
service: string
427-
Name of the service to query: 'site', 'stats', etc.
428-
ssl_check: bool, optional
429-
If True, check SSL certificates, if False, do not check SSL,
430-
default is True
427+
Name of the service to query: 'dv', 'iv', 'site', or 'stat'.
431428
ssl_check: bool, optional
432429
If True, check SSL certificates, if False, do not check SSL,
433430
default is True
@@ -437,7 +434,9 @@ def query_waterservices(
437434
Keyword Arguments
438435
----------------
439436
bBox: string
440-
7-digit Hydrologic Unit Code (HUC)
437+
Bounding box of decimal latitude and longitude values, given as
438+
west longitude, south latitude, east longitude, north latitude,
439+
separated by commas
441440
startDT: string
442441
Start date (e.g., '2017-12-31')
443442
endDT: string
@@ -484,7 +483,7 @@ def get_dv(
484483
"""
485484
Get daily values data from NWIS and return it as a ``pandas.DataFrame``.
486485
487-
.. note:
486+
.. note::
488487
489488
If no start or end date are provided, only the most recent record
490489
is returned.
@@ -511,8 +510,8 @@ def get_dv(
511510
Returns
512511
-------
513512
df: ``pandas.DataFrame``
514-
Times series data from the NWIS JSON
515-
md: :obj:`dataretrieval.utils.Metadata`
513+
Time series data from the NWIS JSON
514+
md: :obj:`dataretrieval.nwis.NWIS_Metadata`
516515
A custom metadata object
517516
518517
Examples
@@ -580,7 +579,7 @@ def get_info(
580579
A contiguous range of decimal latitude and longitude, starting with the
581580
west longitude, then the south latitude, then the east longitude, and
582581
then the north latitude with each value separated by a comma. The
583-
product of the range of latitude range and longitude cannot exceed 25
582+
product of the range of latitude and longitude cannot exceed 25
584583
degrees. Whole or decimal degrees must be specified, up to six digits
585584
of precision. Minutes and seconds are not allowed.
586585
countyCd: string or list of strings
@@ -625,7 +624,7 @@ def get_info(
625624
-------
626625
df: ``pandas.DataFrame``
627626
Site data from the NWIS web service
628-
md: :obj:`dataretrieval.utils.Metadata`
627+
md: :obj:`dataretrieval.nwis.NWIS_Metadata`
629628
A custom metadata object
630629
631630
Examples
@@ -645,7 +644,7 @@ def get_info(
645644
(
646645
"WARNING: Starting in March 2024, the NWIS qw data endpoint is "
647646
"retiring and no longer receives updates. For more information, "
648-
"refer to https://waterdata.usgs.gov.nwis/qwdata and "
647+
"refer to https://waterdata.usgs.gov/nwis/qwdata and "
649648
"https://doi-usgs.github.io/dataRetrieval/articles/Status.html "
650649
"or email CompTools@usgs.gov."
651650
),
@@ -701,8 +700,8 @@ def get_iv(
701700
Returns
702701
-------
703702
df: ``pandas.DataFrame``
704-
Times series data from the NWIS JSON
705-
md: :obj:`dataretrieval.utils.Metadata`
703+
Time series data from the NWIS JSON
704+
md: :obj:`dataretrieval.nwis.NWIS_Metadata`
706705
A custom metadata object
707706
708707
Examples
@@ -734,7 +733,7 @@ def get_iv(
734733

735734

736735
def get_pmcodes(**kwargs: Any) -> NoReturn:
737-
"""Defunct: use ``get_reference_table(collection='parameter-codes')``."""
736+
"""Defunct: use ``waterdata.get_reference_table(collection='parameter-codes')``."""
738737
raise NameError(
739738
"`nwis.get_pmcodes` has been replaced "
740739
"with `get_reference_table(collection='parameter-codes')`."
@@ -762,7 +761,7 @@ def get_ratings(
762761
Parameters
763762
----------
764763
site: string, optional, default is None
765-
USGS site number. This is usually an 8 digit number as a string.
764+
USGS site number. This is usually an 8 digit number as a string.
766765
If the nwis parameter site_no is supplied, it will overwrite the site
767766
parameter
768767
file_type: string, default is "base"
@@ -773,11 +772,11 @@ def get_ratings(
773772
**kwargs: optional
774773
If supplied, will be used as query parameters
775774
776-
Return
777-
------
775+
Returns
776+
-------
778777
df: ``pandas.DataFrame``
779778
Formatted requested data
780-
md: :obj:`dataretrieval.utils.Metadata`
779+
md: :obj:`dataretrieval.nwis.NWIS_Metadata`
781780
A custom metadata object
782781
783782
Examples
@@ -819,11 +818,11 @@ def what_sites(
819818
**kwargs: optional
820819
Accepts the same parameters as :obj:`dataretrieval.nwis.get_info`
821820
822-
Return
823-
------
821+
Returns
822+
-------
824823
df: ``pandas.DataFrame``
825824
Formatted requested data
826-
md: :obj:`dataretrieval.utils.Metadata`
825+
md: :obj:`dataretrieval.nwis.NWIS_Metadata`
827826
A custom metadata object
828827
829828
Examples
@@ -870,7 +869,7 @@ def get_record(
870869
Parameters
871870
----------
872871
sites: string or list of strings, optional, default is None
873-
List or comma delimited string of site.
872+
List or comma delimited string of sites.
874873
start: string, optional, default is None
875874
Starting date of record (YYYY-MM-DD)
876875
end: string, optional, default is None
@@ -882,7 +881,7 @@ def get_record(
882881
If True, return data in wide format with multiple samples per row and
883882
one row per time, default is True
884883
datetime_index : bool, optional
885-
If True, create a datetime index. default is True
884+
If True, create a datetime index. Default is True
886885
state: string, optional, default is None
887886
full name, abbreviation or id
888887
service: string, default is 'iv'
@@ -893,7 +892,7 @@ def get_record(
893892
- 'peaks': discharge peaks
894893
- 'gwlevels': (defunct) use `waterdata.get_continuous`,
895894
`waterdata.get_daily`, or `waterdata.get_field_measurements`
896-
- 'pmcodes': (defunct) use `get_reference_table`
895+
- 'pmcodes': (defunct) use `waterdata.get_reference_table`
897896
- 'water_use': (defunct) no replacement available
898897
- 'ratings': get rating table
899898
- 'stat': get statistics
@@ -1021,9 +1020,7 @@ def _read_json(json: dict[str, Any]) -> pd.DataFrame:
10211020
Returns
10221021
-------
10231022
df: ``pandas.DataFrame``
1024-
Times series data from the NWIS JSON
1025-
md: :obj:`dataretrieval.utils.Metadata`
1026-
A custom metadata object
1023+
Time series data from the NWIS JSON
10271024
10281025
"""
10291026
all_site_dfs = []
@@ -1033,7 +1030,7 @@ def _read_json(json: dict[str, Any]) -> pd.DataFrame:
10331030
]
10341031

10351032
# create a list of indexes for each change in site no
1036-
# for example, [0, 21, 22] would be the first and last indeces
1033+
# for example, [0, 21, 22] would be the first and last indices
10371034
index_list = [0]
10381035
index_list.extend(
10391036
[i + 1 for i, (a, b) in enumerate(zip(site_list[:-1], site_list[1:])) if a != b]
@@ -1127,7 +1124,7 @@ class NWIS_Metadata(BaseMetadata):
11271124
----------
11281125
url : str
11291126
Response url
1130-
query_time: datetme.timedelta
1127+
query_time: datetime.timedelta
11311128
Response elapsed time
11321129
header: httpx.Headers
11331130
Response headers
@@ -1152,11 +1149,6 @@ def __init__(self, response: httpx.Response, **parameters: Any) -> None:
11521149
parameters: unpacked dictionary
11531150
Unpacked dictionary of the parameters supplied in the request
11541151
1155-
Returns
1156-
-------
1157-
md: :obj:`dataretrieval.nwis.NWIS_Metadata`
1158-
A ``dataretrieval`` custom :obj:`dataretrieval.nwis.NWIS_Metadata` object.
1159-
11601152
"""
11611153
super().__init__(response)
11621154

@@ -1177,8 +1169,8 @@ def site_info(self) -> tuple[pd.DataFrame, BaseMetadata] | None:
11771169
``huc``, ``countyCd`` or ``bBox`` (``site_no`` is preferred over
11781170
``sites`` if both are present); ``None`` otherwise.
11791171
1180-
Return
1181-
------
1172+
Returns
1173+
-------
11821174
df: ``pandas.DataFrame``
11831175
Formatted requested data from calling `nwis.what_sites`
11841176
md: :obj:`dataretrieval.nwis.NWIS_Metadata`

0 commit comments

Comments
 (0)