@@ -195,7 +195,8 @@ def get_daily(
195195 ``QuotaExhausted``) exception from a previous call. The chunker
196196 consults its ``chunk_manifest`` to skip already-completed
197197 sub-requests and fetch only the remainder. Pass the same other
198- kwargs as the original call. See ``get_daily`` for a worked
198+ kwargs as the original call. See the
199+ :ref:`waterdata-chunking-resume` user guide for a worked
199200 retry-loop example.
200201
201202 Returns
@@ -253,51 +254,6 @@ def get_daily(
253254 ... parameter_code="00060",
254255 ... time="P7D",
255256 ... )
256-
257- >>> # Resume loop: a heavy chunked query may exhaust the hourly
258- >>> # rate-limit budget partway through or hit a transient upstream
259- >>> # error. Catch ``PartialResult``, accumulate the partial frames,
260- >>> # and re-call with ``resume_from=`` to fetch only the
261- >>> # outstanding chunks. The USGS API rate-limit window is one
262- >>> # hour, so a total retry window of one hour is a sensible
263- >>> # ceiling — anything longer means the failure is structural,
264- >>> # not transient, and the loop should surface the error.
265- >>> import time
266- >>> import pandas as pd
267- >>> from dataretrieval import waterdata
268- >>> from dataretrieval.waterdata.chunking import PartialResult
269- >>>
270- >>> sites = sites_df["monitoring_location_id"].tolist()
271- >>> deadline = time.monotonic() + 3600 # one hour cap
272- >>> partials = []
273- >>> md = None # carries the latest chunk_manifest between attempts
274- >>> attempt = 0
275- >>> while True:
276- ... try:
277- ... df, md = waterdata.get_daily(
278- ... monitoring_location_id=sites,
279- ... parameter_code="00060",
280- ... time="P7D",
281- ... resume_from=md, # ``None`` on the first attempt
282- ... )
283- ... break # full result fetched
284- ... except PartialResult as exc:
285- ... partials.append(exc.partial_frame)
286- ... md = exc.partial_metadata
287- ... if time.monotonic() >= deadline:
288- ... raise TimeoutError(
289- ... f"Could not complete chunked query within one hour "
290- ... f"({md.chunk_manifest.completed}/"
291- ... f"{md.chunk_manifest.total} chunks done)."
292- ... ) from exc
293- ... attempt += 1
294- ... # Exponential backoff, capped at 10 minutes. Quota-
295- ... # reset failures benefit from a longer wait; transient
296- ... # transport errors clear quickly. ``min(...)`` ensures
297- ... # a tight cap; the outer deadline ensures we never wait
298- ... # past one hour total.
299- ... time.sleep(min(60 * 2 ** (attempt - 1), 600))
300- >>> full = pd.concat([*partials, df], ignore_index=True)
301257 """
302258 service = "daily"
303259 output_id = "daily_id"
@@ -458,7 +414,8 @@ def get_continuous(
458414 ``QuotaExhausted``) exception from a previous call. The chunker
459415 consults its ``chunk_manifest`` to skip already-completed
460416 sub-requests and fetch only the remainder. Pass the same other
461- kwargs as the original call. See ``get_daily`` for a worked
417+ kwargs as the original call. See the
418+ :ref:`waterdata-chunking-resume` user guide for a worked
462419 retry-loop example.
463420
464421 Returns
@@ -774,7 +731,8 @@ def get_monitoring_locations(
774731 ``QuotaExhausted``) exception from a previous call. The chunker
775732 consults its ``chunk_manifest`` to skip already-completed
776733 sub-requests and fetch only the remainder. Pass the same other
777- kwargs as the original call. See ``get_daily`` for a worked
734+ kwargs as the original call. See the
735+ :ref:`waterdata-chunking-resume` user guide for a worked
778736 retry-loop example.
779737
780738 Returns
@@ -1005,7 +963,8 @@ def get_time_series_metadata(
1005963 ``QuotaExhausted``) exception from a previous call. The chunker
1006964 consults its ``chunk_manifest`` to skip already-completed
1007965 sub-requests and fetch only the remainder. Pass the same other
1008- kwargs as the original call. See ``get_daily`` for a worked
966+ kwargs as the original call. See the
967+ :ref:`waterdata-chunking-resume` user guide for a worked
1009968 retry-loop example.
1010969
1011970 Returns
@@ -1210,7 +1169,8 @@ def get_combined_metadata(
12101169 ``QuotaExhausted``) exception from a previous call. The chunker
12111170 consults its ``chunk_manifest`` to skip already-completed
12121171 sub-requests and fetch only the remainder. Pass the same other
1213- kwargs as the original call. See ``get_daily`` for a worked
1172+ kwargs as the original call. See the
1173+ :ref:`waterdata-chunking-resume` user guide for a worked
12141174 retry-loop example.
12151175
12161176 Returns
@@ -1435,7 +1395,8 @@ def get_latest_continuous(
14351395 ``QuotaExhausted``) exception from a previous call. The chunker
14361396 consults its ``chunk_manifest`` to skip already-completed
14371397 sub-requests and fetch only the remainder. Pass the same other
1438- kwargs as the original call. See ``get_daily`` for a worked
1398+ kwargs as the original call. See the
1399+ :ref:`waterdata-chunking-resume` user guide for a worked
14391400 retry-loop example.
14401401
14411402 Returns
@@ -1640,7 +1601,8 @@ def get_latest_daily(
16401601 ``QuotaExhausted``) exception from a previous call. The chunker
16411602 consults its ``chunk_manifest`` to skip already-completed
16421603 sub-requests and fetch only the remainder. Pass the same other
1643- kwargs as the original call. See ``get_daily`` for a worked
1604+ kwargs as the original call. See the
1605+ :ref:`waterdata-chunking-resume` user guide for a worked
16441606 retry-loop example.
16451607
16461608 Returns
@@ -1836,7 +1798,8 @@ def get_field_measurements(
18361798 ``QuotaExhausted``) exception from a previous call. The chunker
18371799 consults its ``chunk_manifest`` to skip already-completed
18381800 sub-requests and fetch only the remainder. Pass the same other
1839- kwargs as the original call. See ``get_daily`` for a worked
1801+ kwargs as the original call. See the
1802+ :ref:`waterdata-chunking-resume` user guide for a worked
18401803 retry-loop example.
18411804
18421805 Returns
@@ -1962,7 +1925,8 @@ def get_field_measurements_metadata(
19621925 ``QuotaExhausted``) exception from a previous call. The chunker
19631926 consults its ``chunk_manifest`` to skip already-completed
19641927 sub-requests and fetch only the remainder. Pass the same other
1965- kwargs as the original call. See ``get_daily`` for a worked
1928+ kwargs as the original call. See the
1929+ :ref:`waterdata-chunking-resume` user guide for a worked
19661930 retry-loop example.
19671931
19681932 Returns
@@ -2094,7 +2058,8 @@ def get_peaks(
20942058 ``QuotaExhausted``) exception from a previous call. The chunker
20952059 consults its ``chunk_manifest`` to skip already-completed
20962060 sub-requests and fetch only the remainder. Pass the same other
2097- kwargs as the original call. See ``get_daily`` for a worked
2061+ kwargs as the original call. See the
2062+ :ref:`waterdata-chunking-resume` user guide for a worked
20982063 retry-loop example.
20992064
21002065 Returns
@@ -2954,7 +2919,8 @@ def get_channel(
29542919 ``QuotaExhausted``) exception from a previous call. The chunker
29552920 consults its ``chunk_manifest`` to skip already-completed
29562921 sub-requests and fetch only the remainder. Pass the same other
2957- kwargs as the original call. See ``get_daily`` for a worked
2922+ kwargs as the original call. See the
2923+ :ref:`waterdata-chunking-resume` user guide for a worked
29582924 retry-loop example.
29592925
29602926 Returns
0 commit comments