|
16 | 16 | get_latest_daily, |
17 | 17 | get_field_measurements, |
18 | 18 | get_time_series_metadata, |
19 | | - get_reference_table |
| 19 | + get_reference_table, |
| 20 | + get_por_stats, |
| 21 | + get_date_range_stats |
20 | 22 | ) |
21 | 23 |
|
22 | 24 | def mock_request(requests_mock, request_url, file_path): |
@@ -265,3 +267,47 @@ def test_get_reference_table_wrong_name(): |
265 | 267 | with pytest.raises(ValueError): |
266 | 268 | get_reference_table("agency-cod") |
267 | 269 |
|
| 270 | +def test_get_por_stats(): |
| 271 | + df,_ = get_por_stats( |
| 272 | + monitoring_location_id="USGS-12451000", |
| 273 | + parameter_code="00060", |
| 274 | + start_date="01-01", |
| 275 | + end_date="01-01" |
| 276 | + ) |
| 277 | + assert type(df) is DataFrame |
| 278 | + assert df['computation'].isin(['median', 'maximum', 'minimum', 'arithmetic_mean', 'percentile']).all() |
| 279 | + assert df['time_of_year'].isin(['01-01', '01']).all() |
| 280 | + assert df.loc[df['computation'] == "minimum", "percentile"].unique().tolist() == [0.0] |
| 281 | + assert df.loc[df['computation'] == "arithmetic_mean", "percentile"].isnull().all() |
| 282 | + |
| 283 | +def test_get_por_stats_expanded_false(): |
| 284 | + df,_ = get_por_stats( |
| 285 | + monitoring_location_id="USGS-12451000", |
| 286 | + parameter_code="00060", |
| 287 | + start_date="01-01", |
| 288 | + end_date="01-01", |
| 289 | + expand_percentiles=False, |
| 290 | + computation_type=["minimum", "percentile"] |
| 291 | + ) |
| 292 | + assert df.shape[0] == 4 |
| 293 | + assert df.shape[1] == 21 |
| 294 | + assert "percentile" not in df.columns |
| 295 | + assert "percentiles" in df.columns |
| 296 | + assert type(df['percentiles'][2]) is list |
| 297 | + assert df.loc[~df['percentiles'].isna(), "value"].isnull().all() |
| 298 | + |
| 299 | +def test_get_date_range_stats(): |
| 300 | + df,_ = get_date_range_stats( |
| 301 | + monitoring_location_id="USGS-12451000", |
| 302 | + parameter_code="00060", |
| 303 | + start_date="2025-01-01", |
| 304 | + end_date="2025-01-01", |
| 305 | + computation_type="maximum" |
| 306 | + ) |
| 307 | + |
| 308 | + assert df.shape[0] == 3 |
| 309 | + assert df.shape[1] == 21 |
| 310 | + assert "interval_type" in df.columns |
| 311 | + assert "percentile" in df.columns |
| 312 | + assert df['interval_type'].isin(['month', 'calendar_year', 'water_year']).all() |
| 313 | + |
0 commit comments