From 192ad0274f36664507bd52bb12ba908a43fe21fe Mon Sep 17 00:00:00 2001 From: veenstrajelmer <60435591+veenstrajelmer@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:15:23 +0200 Subject: [PATCH] Return all measurements amount (#115) * fixed bug by unindenting code * added test * updated history.rst --- HISTORY.rst | 1 + ddlpy/ddlpy.py | 8 ++++---- tests/test_ddlpy.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index ece9261..66b141e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -6,6 +6,7 @@ UNRELEASED ------------------ * avoid timezone conversion if tz-naive `ddlpy.dataframe_to_xarray` in https://github.com/Deltares/ddlpy/pull/106 * added some missing dependencies in https://github.com/Deltares/ddlpy/pull/108 +* `ddlpy.measurements_amount()` now returns all amounts in https://github.com/Deltares/ddlpy/pull/115 0.5.0 (2024-04-26) ------------------ diff --git a/ddlpy/ddlpy.py b/ddlpy/ddlpy.py index f4d5fd4..5b2ae00 100644 --- a/ddlpy/ddlpy.py +++ b/ddlpy/ddlpy.py @@ -262,10 +262,10 @@ def measurements_amount(location:pd.Series, start_date:(str,pd.Timestamp), end_d df = df[["AantalMetingen"]] df_list.append(df) - # concatenate and sum duplicated index - df_amount = pd.concat(df_list).sort_index() - df_amount = df_amount.groupby(df_amount.index).sum() - return df_amount + # concatenate and sum duplicated index + df_amount = pd.concat(df_list).sort_index() + df_amount = df_amount.groupby(df_amount.index).sum() + return df_amount def _combine_waarnemingenlijst(result, location): diff --git a/tests/test_ddlpy.py b/tests/test_ddlpy.py index 11cf11c..a04b244 100755 --- a/tests/test_ddlpy.py +++ b/tests/test_ddlpy.py @@ -107,6 +107,21 @@ def test_measurements_amount(location): assert data_amount_jaar.index.str.len()[0] == 4 +def test_measurements_amount_multipleblocks(location): + # in 1993 the WaardeBepalingsmethode changes from + # other:F001 (Rekenkundig gemiddelde waarde over vorige 10 minuten) to + # other:F007 (Rekenkundig gemiddelde waarde over vorige 5 en volgende 5 minuten) + date_min = "1990-01-01" + date_max = "1995-01-01" + # if we pass one row to the measurements function you can get all the measurements + df_amount = ddlpy.measurements_amount(location, date_min, date_max) + + index_expected = np.array(['1990', '1991', '1992', '1993', '1994', '1995']) + values_expected = np.array([52554, 52560, 52704, 52560, 52560, 7]) + assert (df_amount.index == index_expected).all() + assert (df_amount["AantalMetingen"].values == values_expected).all() + + def test_measurements_latest(location): """measurements for a location """ latest = ddlpy.measurements_latest(location)