Skip to content

Commit 358ddd2

Browse files
committed
tests(IHmethod): add test for handling inadequate input data
1 parent 584a1fa commit 358ddd2

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

pydrograph/baseflow.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ def IHmethod(Qseries, block_length=5, tp=0.9, interp_semilog=True, freq='D'):
120120
freq : str or DateOffset, default ‘D’
121121
Any `pandas frequency alias <https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html#timeseries-offset-aliases>`_
122122
Regular time interval that forms the basis for base-flow separation. Input data are
123-
resampled to this frequency, and block lengths represent N repetitions
124-
of the time increment. By default, days ('D'), which is what all previous BFI methods
123+
resampled to this frequency, and block lengths represent the number of time increments
124+
of the frequency. By default, days ('D'), which is what all previous BFI methods
125125
are based on. Note that this is therefore an experimental option; it is up to the user t
126126
o verify any results produced by other frequencies.
127127
@@ -144,6 +144,11 @@ def IHmethod(Qseries, block_length=5, tp=0.9, interp_semilog=True, freq='D'):
144144
will differ from those produced by the BFI program.
145145
146146
"""
147+
if len(Qseries) < 2 * block_length:
148+
raise ValueError('Input Series must be at '
149+
'least two block lengths\nblock_length: '
150+
'{}\n{}'.format(block_length, Qseries))
151+
147152
# convert flow values to numeric if they are objects
148153
# (pandas will cast column as objects if there are strings such as "ICE")
149154
# coerce any strings into np.nan values

pydrograph/tests/test_baseflow.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,23 @@ def test_IHmethod(test_data, block_length, interp_semilog, freq):
2020
interp_semilog=interp_semilog)
2121
minimum_points = ~results.block_Qmin.isna()
2222
assert np.all(results.loc[minimum_points, 'block_Qmin'] <= results.loc[minimum_points, 'Q'])
23+
24+
25+
@pytest.mark.parametrize('data', (pytest.param(pd.Series(),
26+
marks=pytest.mark.xfail(reason="index isn't datetime")),
27+
pytest.param(pd.Series(index=pd.to_datetime([])),
28+
marks=pytest.mark.xfail(reason="index isn't datetime")),
29+
pytest.param(pd.Series([15.2, 14.8, 14.5, 14.2],
30+
index=pd.date_range('2020-09-30', '2020-10-03')),
31+
marks=pytest.mark.xfail(reason="index isn't datetime")),
32+
pd.Series([15.2, 14.8, 14.5, 14.2, 13.9, 13.8, 13.8, 13.8, 13.8, 13.8],
33+
index=pd.date_range('2020-01-01', '2020-01-10'))
34+
)
35+
)
36+
def test_IHmethod_with_not_enough_data(data):
37+
results = IHmethod(data)
38+
j=2
39+
40+
41+
42+

0 commit comments

Comments
 (0)