Skip to content

Commit b9e4600

Browse files
committed
usgs: Handle dataretrieval state codes
dataretrieval changed the datatype of `state_codes` from a list to a dict. With this commit we handle this change on searvey side. Fixes #143
1 parent 28cb4b5 commit b9e4600

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

searvey/usgs.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# `dataretrieval` package developed by USGS is used for the USGS stations: https://usgs-python.github.io/dataretrieval/
22
#
3-
# This pacakge is a thin wrapper around NWIS _REST API: https://waterservices.usgs.gov/rest/
3+
# This package is a thin wrapper around NWIS _REST API: https://waterservices.usgs.gov/rest/
44
# We take the return values from `dataretrieval` to be the original data
55
from __future__ import annotations
66

@@ -22,7 +22,7 @@
2222
import pandas as pd
2323
import xarray as xr
2424
from dataretrieval import nwis
25-
from dataretrieval.codes import state_codes
25+
from dataretrieval.codes import state_codes as _DATARETRIEVAL_STATE_CODES
2626
from dataretrieval.utils import BaseMetadata
2727
from shapely.geometry import MultiPolygon
2828
from shapely.geometry import Polygon
@@ -43,6 +43,12 @@
4343
# This will stop working if pandas switches its versioning scheme to CalVer or something...
4444
_PANDAS_MAJOR_VERSION = int(importlib.metadata.version("pandas").split(".")[0])
4545

46+
# https://github.com/DOI-USGS/dataretrieval-python/compare/v1.0.8...v1.0.9
47+
if isinstance(_DATARETRIEVAL_STATE_CODES, list):
48+
STATE_CODES = sorted(_DATARETRIEVAL_STATE_CODES)
49+
else:
50+
STATE_CODES = sorted(_DATARETRIEVAL_STATE_CODES.values())
51+
4652
# constants
4753
USGS_OUTPUT_OF_INTEREST = (
4854
"elevation", # Overlaps some of the specific codes below
@@ -156,7 +162,7 @@ def _get_all_usgs_stations(normalize: bool = True) -> gpd.GeoDataFrame:
156162
"hasDataType": dtp,
157163
}
158164
for st, dtp in product(
159-
state_codes,
165+
STATE_CODES,
160166
USGS_OUTPUT_TYPE,
161167
)
162168
],

0 commit comments

Comments
 (0)