Skip to content

Commit cc6f5c2

Browse files
committed
make ref table function way simpler and more efficient
1 parent 67444e5 commit cc6f5c2

2 files changed

Lines changed: 14 additions & 23 deletions

File tree

dataretrieval/waterdata/api.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,7 @@ def get_field_measurements(
13941394

13951395
return get_ogc_data(args, output_id, service)
13961396

1397+
13971398
def get_reference_table(
13981399
collection: str,
13991400
limit: Optional[int] = None,
@@ -1426,29 +1427,19 @@ def get_reference_table(
14261427
f"Valid options are: {valid_code_services}."
14271428
)
14281429

1429-
req = _construct_api_requests(
1430-
service=collection,
1431-
limit=limit,
1432-
skip_geometry=True,
1433-
)
1434-
# Run API request and iterate through pages if needed
1435-
return_list, response = _walk_pages(
1436-
geopd=False, req=req
1437-
)
1438-
1439-
# Give ID column a more meaningful name
1440-
if collection.endswith("s"):
1441-
return_list = return_list.rename(
1442-
columns={"id": f"{collection[:-1].replace('-', '_')}_id"}
1443-
)
1430+
# Give ID column the collection name with underscores
1431+
if collection.endswith("s") and collection != "counties":
1432+
output_id = f"{collection[:-1].replace('-', '_')}"
1433+
elif collection == "counties":
1434+
output_id = "county"
14441435
else:
1445-
return_list = return_list.rename(
1446-
columns={"id": f"{collection.replace('-', '_')}_id"}
1447-
)
1448-
1449-
# Create metadata object from response
1450-
metadata = BaseMetadata(response)
1451-
return return_list, metadata
1436+
output_id = f"{collection.replace('-', '_')}"
1437+
1438+
return get_ogc_data(
1439+
args={},
1440+
output_id=output_id,
1441+
service=collection
1442+
)
14521443

14531444

14541445
def get_codes(code_service: CODE_SERVICES) -> pd.DataFrame:

tests/waterdata_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def test_get_time_series_metadata():
248248

249249
def test_get_reference_table():
250250
df, md = get_reference_table("agency-codes")
251-
assert "agency_code_id" in df.columns
251+
assert "agency_code" in df.columns
252252
assert df.shape[0] > 0
253253
assert hasattr(md, 'url')
254254
assert hasattr(md, 'query_time')

0 commit comments

Comments
 (0)