Skip to content

Commit 193205e

Browse files
committed
change function names, add more to documentation
1 parent 8f2bc0a commit 193205e

3 files changed

Lines changed: 42 additions & 24 deletions

File tree

dataretrieval/waterdata/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
get_codes,
1515
get_continuous,
1616
get_daily,
17-
get_date_range_stats,
17+
get_stats_date_range,
1818
get_field_measurements,
1919
get_latest_continuous,
2020
get_latest_daily,
2121
get_monitoring_locations,
22-
get_por_stats,
22+
get_stats_por,
2323
get_reference_table,
2424
get_samples,
2525
get_time_series_metadata,
@@ -35,12 +35,12 @@
3535
"get_codes",
3636
"get_continuous",
3737
"get_daily",
38-
"get_date_range_stats",
38+
"get_stats_date_range",
3939
"get_field_measurements",
4040
"get_latest_continuous",
4141
"get_latest_daily",
4242
"get_monitoring_locations",
43-
"get_por_stats",
43+
"get_stats_por",
4444
"get_reference_table",
4545
"get_samples",
4646
"get_time_series_metadata",

dataretrieval/waterdata/api.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,7 @@ def get_samples(
17471747

17481748
return df, BaseMetadata(response)
17491749

1750-
def get_por_stats(
1750+
def get_stats_por(
17511751
approval_status: Optional[str] = None,
17521752
computation_type: Optional[Union[str, list[str]]] = None,
17531753
country_code: Optional[Union[str, list[str]]] = None,
@@ -1828,17 +1828,26 @@ def get_por_stats(
18281828
thresholds in the "values" and "percentiles" columns, respectively.
18291829
When `expand_percentiles` is set to True (default), each value and
18301830
percentile threshold specific to a computation id are returned as
1831-
individual rows in the dataframe. Missing percentile values expressed
1832-
as 'nan' in the list of string values are removed from the dataframe
1833-
to save space.
1831+
individual rows in the dataframe, with the value reported in the
1832+
"value" column and the corresponding percentile reported in a
1833+
"percentile" column (and the "values" and "percentiles" columns
1834+
are removed). Missing percentile values expressed as 'nan' in the
1835+
list of string values are removed from the dataframe to save space.
1836+
Setting `expand_percentiles` to False retains the "values" and
1837+
"percentiles" columns produced by the service. Including
1838+
both 'percentiles' and one or more other statistics ('median',
1839+
'minimum', 'maximum', or 'arithmetic_mean') in the `computation_type`
1840+
argument will return both the "values" column, containing the list
1841+
of percentile threshold values, and a "value" column, containing
1842+
the singular summary value for the other statistics.
18341843
18351844
Examples
18361845
--------
18371846
.. code::
18381847
18391848
>>> # Get daily, monthly, and annual percentiles for streamflow at
18401849
>>> # a monitoring location of interest
1841-
>>> df, md = dataretrieval.waterdata.get_por_stats(
1850+
>>> df, md = dataretrieval.waterdata.get_stats_por(
18421851
... monitoring_location_id="USGS-05114000",
18431852
... parameter_code="00060",
18441853
... computation_type="percentile"
@@ -1847,7 +1856,7 @@ def get_por_stats(
18471856
>>> # Get all daily and monthly statistics for the month of January
18481857
>>> # over the entire period of record for streamflow and gage height
18491858
>>> # at a monitoring location of interest
1850-
>>> df, md = dataretrieval.waterdata.get_por_stats(
1859+
>>> df, md = dataretrieval.waterdata.get_stats_por(
18511860
... monitoring_location_id="USGS-05114000",
18521861
... parameter_code=["00060", "00065"],
18531862
... start_date="01-01",
@@ -1866,7 +1875,7 @@ def get_por_stats(
18661875
expand_percentiles=expand_percentiles
18671876
)
18681877

1869-
def get_date_range_stats(
1878+
def get_stats_date_range(
18701879
approval_status: Optional[str] = None,
18711880
computation_type: Optional[Union[str, list[str]]] = None,
18721881
country_code: Optional[Union[str, list[str]]] = None,
@@ -1948,17 +1957,26 @@ def get_date_range_stats(
19481957
thresholds in the "values" and "percentiles" columns, respectively.
19491958
When `expand_percentiles` is set to True (default), each value and
19501959
percentile threshold specific to a computation id are returned as
1951-
individual rows in the dataframe. Missing percentile values expressed
1952-
as 'nan' in the list of string values are removed from the dataframe
1953-
to save space.
1960+
individual rows in the dataframe, with the value reported in the
1961+
"value" column and the corresponding percentile reported in a
1962+
"percentile" column (and the "values" and "percentiles" columns
1963+
are removed). Missing percentile values expressed as 'nan' in the
1964+
list of string values are removed from the dataframe to save space.
1965+
Setting `expand_percentiles` to False retains the "values" and
1966+
"percentiles" columns produced by the service. Including
1967+
both 'percentiles' and one or more other statistics ('median',
1968+
'minimum', 'maximum', or 'arithmetic_mean') in the `computation_type`
1969+
argument will return both the "values" column, containing the list
1970+
of percentile threshold values, and a "value" column, containing
1971+
the singular summary value for the other statistics.
19541972
19551973
Examples
19561974
--------
19571975
.. code::
19581976
19591977
>>> # Get monthly and yearly medians for streamflow at streams in Rhode Island
19601978
>>> # from calendar year 2024.
1961-
>>> df, md = dataretrieval.waterdata.get_date_range_stats(
1979+
>>> df, md = dataretrieval.waterdata.get_stats_date_range(
19621980
... state_code="US:44", # State code for Rhode Island
19631981
... parameter_code="00060",
19641982
... site_type_code="ST",
@@ -1969,7 +1987,7 @@ def get_date_range_stats(
19691987
19701988
>>> # Get monthly and yearly minimum and maximums for gage height at
19711989
>>> # a monitoring location of interest
1972-
>>> df, md = dataretrieval.waterdata.get_date_range_stats(
1990+
>>> df, md = dataretrieval.waterdata.get_stats_date_range(
19731991
... monitoring_location_id="USGS-05114000",
19741992
... parameter_code="00065",
19751993
... computation_type=["minimum", "maximum"]

tests/waterdata_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
get_field_measurements,
1818
get_time_series_metadata,
1919
get_reference_table,
20-
get_por_stats,
21-
get_date_range_stats
20+
get_stats_por,
21+
get_stats_date_range
2222
)
2323

2424
def mock_request(requests_mock, request_url, file_path):
@@ -267,8 +267,8 @@ def test_get_reference_table_wrong_name():
267267
with pytest.raises(ValueError):
268268
get_reference_table("agency-cod")
269269

270-
def test_get_por_stats():
271-
df,_ = get_por_stats(
270+
def test_get_stats_por():
271+
df,_ = get_stats_por(
272272
monitoring_location_id="USGS-12451000",
273273
parameter_code="00060",
274274
start_date="01-01",
@@ -279,8 +279,8 @@ def test_get_por_stats():
279279
assert df.loc[df['computation'] == "minimum", "percentile"].unique().tolist() == [0.0]
280280
assert df.loc[df['computation'] == "arithmetic_mean", "percentile"].isnull().all()
281281

282-
def test_get_por_stats_expanded_false():
283-
df,_ = get_por_stats(
282+
def test_get_stats_por_expanded_false():
283+
df,_ = get_stats_por(
284284
monitoring_location_id="USGS-12451000",
285285
parameter_code="00060",
286286
start_date="01-01",
@@ -295,8 +295,8 @@ def test_get_por_stats_expanded_false():
295295
assert type(df['percentiles'][2]) is list
296296
assert df.loc[~df['percentiles'].isna(), "value"].isnull().all()
297297

298-
def test_get_date_range_stats():
299-
df,_ = get_date_range_stats(
298+
def test_get_stats_date_range():
299+
df,_ = get_stats_date_range(
300300
monitoring_location_id="USGS-12451000",
301301
parameter_code="00060",
302302
start_date="2025-01-01",

0 commit comments

Comments
 (0)