hyriver / pygeohydro

A part of HyRiver software stack for accessing hydrology data through web services
https://docs.hyriver.io
Other
68 stars 23 forks source link

NWIS async retrieval error #124

Closed dgketchum closed 1 month ago

dgketchum commented 2 months ago

What happened?

Trying to retrieve a single USGS stream gage record raises an exception from async_retriever.

What did you expect to happen?

To get a returned DataFrame of the gage data.

Minimal Complete Verifiable Example

'''
from pygeohydro import NWIS

nwis = NWIS()
observed = nwis.get_streamflow('12340500', ('2023-01-01', '2023-12-31'))
print(observed.iloc[0])
'''

MVCE confirmation

Relevant log output

Traceback (most recent call last):
  File "C:\Users\dketchum\PycharmProjects\hytest\hydrograph_comparison\pygeo_problem.py", line 4, in <module>
    observed = nwis.get_streamflow('12340500', ('2023-01-01', '2023-12-31'))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dketchum\AppData\Local\miniforge3\envs\hyt\Lib\site-packages\pygeohydro\nwis.py", line 713, in get_streamflow
    siteinfo = cls.get_info(queries)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dketchum\AppData\Local\miniforge3\envs\hyt\Lib\site-packages\pygeohydro\nwis.py", line 407, in get_info
    resp = ar.retrieve_text(urls)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dketchum\AppData\Local\miniforge3\envs\hyt\Lib\site-packages\async_retriever\async_retriever.py", line 500, in retrieve_text
    return retrieve(
           ^^^^^^^^^
  File "C:\Users\dketchum\AppData\Local\miniforge3\envs\hyt\Lib\site-packages\async_retriever\async_retriever.py", line 433, in retrieve
    resp = [r for _, r in sorted(tlz.concat(results))]
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dketchum\AppData\Local\miniforge3\envs\hyt\Lib\site-packages\async_retriever\async_retriever.py", line 431, in <genexpr>
    results = (loop.run_until_complete(session(url_kwds=c)) for c in chunked_reqs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dketchum\AppData\Local\miniforge3\envs\hyt\Lib\asyncio\base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\dketchum\AppData\Local\miniforge3\envs\hyt\Lib\site-packages\async_retriever\async_retriever.py", line 236, in async_session_with_cache
    return await asyncio.gather(*tasks)  # pyright: ignore[reportReturnType]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dketchum\AppData\Local\miniforge3\envs\hyt\Lib\site-packages\async_retriever\_utils.py", line 81, in retriever
    async with session(url, **s_kwds) as response:
  File "C:\Users\dketchum\AppData\Local\miniforge3\envs\hyt\Lib\site-packages\aiohttp\client.py", line 1364, in __aexit__
    await self._resp.__aexit__(exc_type, exc, tb)
          ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'CachedResponse' object has no attribute '__aexit__'. Did you mean: '__init__'?

Anything else we need to know?

Python 3.12 new conda env built today.

Environment

Package Version -------------------- ----------- affine 2.4.0 aiohappyeyeballs 2.4.0 aiohttp 3.10.6 aiohttp-client-cache 0.11.1 aiosignal 1.3.1 aiosqlite 0.20.0 asciitree 0.3.3 async-retriever 0.17.1 attrs 24.2.0 branca 0.8.0 Brotli 1.1.0 cattrs 24.1.2 certifi 2024.8.30 cftime 1.6.4 charset-normalizer 3.3.2 click 8.1.7 click-plugins 1.1.1 cligj 0.7.2 cloudpickle 3.0.0 colorama 0.4.6 contourpy 1.3.0 cycler 0.12.1 cytoolz 0.12.3 dask 2024.9.0 defusedxml 0.7.1 distributed 2024.9.0 fasteners 0.19 folium 0.17.0 fonttools 4.54.1 frozenlist 1.4.1 fsspec 2024.9.0 geopandas 1.0.1 h5netcdf 1.3.0 h5py 3.12.1 hydrosignatures 0.17.1 idna 3.10 itsdangerous 2.2.0 Jinja2 3.1.4 joblib 1.4.2 kiwisolver 1.4.7 locket 1.0.0 lxml 5.3.0 MarkupSafe 2.1.5 matplotlib 3.9.2 msgpack 1.1.0 multidict 6.1.0 netCDF4 1.7.1.post2 networkx 3.3 numcodecs 0.13.0 numpy 2.1.1 OWSLib 0.31.0 packaging 24.1 pandas 2.2.3 partd 1.4.2 pillow 10.4.0 pip 24.2 platformdirs 4.3.6 psutil 6.0.0 pyarrow 17.0.0 pygeohydro 0.17.1 pygeoogc 0.17.1 pygeoutils 0.17.1 pynhd 0.17.1 pyogrio 0.9.0 pyparsing 3.1.4 pyproj 3.6.1 python-dateutil 2.9.0.post0 pytz 2024.2 PyYAML 6.0.2 rasterio 1.4.0 requests 2.32.3 requests-cache 1.2.1 rioxarray 0.17.0 scipy 1.14.1 setuptools 75.1.0 shapely 2.0.6 six 1.16.0 sortedcontainers 2.4.0 tblib 3.0.0 toolz 0.12.1 tornado 6.4.1 typing_extensions 4.12.2 tzdata 2024.2 ujson 5.10.0 url-normalize 1.4.3 urllib3 2.2.3 wheel 0.44.0 xarray 2024.9.0 xyzservices 2024.9.0 yarl 1.12.1 zarr 2.18.3 zict 3.0.0
cheginit commented 2 months ago

Thanks for reporting this. The issue is caused by aiohttp-client-cache. It's being addressed soon. Once its developers address the issue, updating aiohttp-client-cache should fix the issue. I will then release a new version to pin the dep for aiohttp-client-cache to the fixed version.

cheginit commented 1 month ago

@dgketchum, HyRiver 0.18 is out now that fixes this issue.

cheginit commented 1 month ago

Please reopen if you have this issue.