Skip to content

Commit

Permalink
return empty dataframe instead of none (#75)
Browse files Browse the repository at this point in the history
* return empty dataframe instead of none

* updates history.rst
  • Loading branch information
veenstrajelmer authored Mar 12, 2024
1 parent 74cc608 commit 34ff9df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ UNRELEASED
* drop `Tijdstip` column in `ddlpy.measurements()` output dataframe to avoid duplication with time index in https://github.com/deltares/ddlpy/pull/52 and https://github.com/deltares/ddlpy/pull/54
* add `ddlpy.measurements_amount()` to retrieve the number of available measurements grouped by day/month/year in https://github.com/Deltares/ddlpy/pull/63
* catch accidentally switched start/end dates in https://github.com/Deltares/ddlpy/pull/65
* in case of no measurements, return empty dataframe instead of None or empty list in https://github.com/Deltares/ddlpy/pull/75

0.1.0 (2019-01-03)
------------------
Expand Down
4 changes: 2 additions & 2 deletions ddlpy/ddlpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ def measurements(location, start_date, end_date, clean_df=True):
continue

if len(measurements) == 0:
# early return in case of no data
# return empty dataframe in case of no data
logger.debug("no data found for this station and time extent")
return
return pd.DataFrame()

measurements = pd.concat(measurements)

Expand Down
8 changes: 8 additions & 0 deletions tests/test_ddlpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def test_measurements_amount(location):
assert data_amount_jaar["Groeperingsperiode"].str.len().iloc[0] == 4


def test_measurements_empty(location):
"""measurements for a location """
start_date = dt.datetime(2153, 1, 1)
end_date = dt.datetime(2153, 1, 2)
measurements = ddlpy.measurements(location, start_date=start_date, end_date=end_date)
assert measurements.empty


def test_measurements(location):
"""measurements for a location """
start_date = dt.datetime(1953, 1, 1)
Expand Down

0 comments on commit 34ff9df

Please sign in to comment.