Skip to content

Commit 709450a

Browse files
committed
fix issue with column name not always being present given the inputs, add more examples
1 parent 4c46ead commit 709450a

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

dataretrieval/waterdata/api.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,6 +1836,28 @@ def get_por_stats(
18361836
individual rows in the dataframe. Missing percentile values expressed
18371837
as 'nan' in the list of string values are removed from the dataframe
18381838
to save space.
1839+
1840+
Examples
1841+
--------
1842+
.. code::
1843+
1844+
>>> # Get daily, monthly, and annual percentiles for streamflow at
1845+
>>> # a monitoring location of interest
1846+
>>> df, md = dataretrieval.waterdata.get_por_stats(
1847+
... monitoring_location_id="USGS-05114000",
1848+
... parameter_code="00060",
1849+
... computation_type="percentile"
1850+
... )
1851+
1852+
>>> # Get all daily and monthly statistics for the month of January
1853+
>>> # over the entire period of record for streamflow and gage height
1854+
>>> # at a monitoring location of interest
1855+
>>> df, md = dataretrieval.waterdata.get_por_stats(
1856+
... monitoring_location_id="USGS-05114000",
1857+
... parameter_code=["00060", "00065"],
1858+
... start_date="01-01",
1859+
... end_date="01-31"
1860+
... )
18391861
"""
18401862
params = {
18411863
k: v

dataretrieval/waterdata/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ def _expand_percentiles(df: pd.DataFrame) -> pd.DataFrame:
913913
percentiles_explode = percentiles_explode.drop(columns=['values', 'percentiles'])
914914

915915
# Merge exploded values back to other metadata/geometry
916-
percentiles = percentiles.drop(columns=['values', 'percentiles', 'value']).merge(percentiles_explode, on='computation_id', how='left')
916+
percentiles = percentiles.drop(columns=['values', 'percentiles', 'value'], errors="ignore").merge(percentiles_explode, on='computation_id', how='left')
917917

918918
# Concatenate back to original
919919
dfs = pd.concat([df.loc[df['computation'] != "percentile"], percentiles]).drop(columns=['values', 'percentiles'])

0 commit comments

Comments
 (0)