diff --git a/dataretrieval/nwis.py b/dataretrieval/nwis.py index 6244798..160c433 100644 --- a/dataretrieval/nwis.py +++ b/dataretrieval/nwis.py @@ -96,7 +96,7 @@ def format_response( if service == "peaks": df = preformat_peaks_response(df) - if gpd is not None and "dec_lat_va" in list(df): + if gpd is not None and "dec_lat_va" in df.columns: geoms = gpd.points_from_xy(df.dec_long_va.values, df.dec_lat_va.values) df = gpd.GeoDataFrame(df, geometry=geoms, crs=_CRS) @@ -993,10 +993,7 @@ def _read_json(json): ) index_list.append(len(site_list)) - for i in range(len(index_list) - 1): - start = index_list[i] # [0] - end = index_list[i + 1] # [21] - + for start, end in zip(index_list[:-1], index_list[1:]): # grab a block containing timeseries 0:21, # which are all from the same site site_block = json["value"]["timeSeries"][start:end] diff --git a/dataretrieval/waterdata/utils.py b/dataretrieval/waterdata/utils.py index 4198e02..ecf99ba 100644 --- a/dataretrieval/waterdata/utils.py +++ b/dataretrieval/waterdata/utils.py @@ -184,9 +184,8 @@ def _format_api_dates( if len(datetime_input) <= 2: # If the list is of length 1, first look for things like "P7D" or dates # already formatted in ISO08601. Otherwise, try to coerce to datetime - if ( - len(datetime_input) == 1 - and re.search(r"P", datetime_input[0], re.IGNORECASE) + if len(datetime_input) == 1 and ( + re.search(r"P", datetime_input[0], re.IGNORECASE) or "/" in datetime_input[0] ): return datetime_input[0] @@ -291,12 +290,13 @@ def _check_ogc_requests(endpoint: str = "daily", req_type: str = "queryables"): Raises ------ - AssertionError + ValueError If req_type is not "queryables" or "schema". requests.HTTPError If the HTTP request returns an unsuccessful status code. """ - assert req_type in ["queryables", "schema"] + if req_type not in ("queryables", "schema"): + raise ValueError(f"req_type must be 'queryables' or 'schema', got {req_type!r}") url = f"{OGC_API_URL}/collections/{endpoint}/{req_type}" resp = requests.get(url, headers=_default_headers()) resp.raise_for_status()