Skip to content

Commit 9236209

Browse files
committed
add back in geometry when skip_geometry is false but properties do not contain geometry
1 parent 171aefc commit 9236209

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

dataretrieval/waterdata/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,11 @@ def _arrange_cols(
653653
df = df.rename(columns={"id": output_id})
654654

655655
# If properties are provided, filter to only those columns
656+
# plus geometry if skip_geometry is False
656657
if properties and not all(pd.isna(properties)):
658+
# Make sure geometry stays in the dataframe if skip_geometry is False
659+
if 'geometry' in df.columns and 'geometry' not in properties:
660+
properties.append('geometry')
657661
# id is technically a valid column from the service, but these
658662
# functions make the name more specific. So, if someone requests
659663
# 'id', give them the output_id column

tests/waterdata_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ def test_get_latest_daily():
214214
assert hasattr(md, 'url')
215215
assert hasattr(md, 'query_time')
216216

217+
def test_get_latest_daily_properties_geometry():
218+
df, md = get_latest_daily(
219+
monitoring_location_id=["USGS-05427718", "USGS-05427719"],
220+
parameter_code=["00060", "00065"],
221+
properties=['monitoring_location_id', 'parameter_code', 'time', 'value', 'unit_of_measure']
222+
)
223+
assert "geometry" in df.columns
224+
assert df.shape[1] == 6
225+
217226
def test_get_field_measurements():
218227
df, md = get_field_measurements(
219228
monitoring_location_id="USGS-05427718",

0 commit comments

Comments
 (0)