Skip to content

Commit

Permalink
Return all measurements amount (#115)
Browse files Browse the repository at this point in the history
* fixed bug by unindenting code

* added test

* updated history.rst
  • Loading branch information
veenstrajelmer authored Oct 8, 2024
1 parent abb0d02 commit 192ad02
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------
Expand Down
8 changes: 4 additions & 4 deletions ddlpy/ddlpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_ddlpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 192ad02

Please sign in to comment.