From ef89553ea0429c9a882ce028f2d7b496904a0bb4 Mon Sep 17 00:00:00 2001 From: Peter Luenenschloss <peter.luenenschloss@ufz.de> Date: Tue, 10 Dec 2019 16:29:07 +0100 Subject: [PATCH] implemented test for aggregate/whiped out senile bugs in aggregate --- saqc/funcs/harm_functions.py | 4 ++-- test/funcs/test_harm_funcs.py | 17 ++++------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/saqc/funcs/harm_functions.py b/saqc/funcs/harm_functions.py index 9933253ef..d5bb8f577 100644 --- a/saqc/funcs/harm_functions.py +++ b/saqc/funcs/harm_functions.py @@ -876,14 +876,14 @@ def aggregate(data, field, flagger, source_freq, target_freq, agg_func=np.mean, else: def aggregator(x): - agg_func(getattr(x.resample(source_freq), sample_func_name)()) + return agg_func(getattr(x.resample(source_freq), sample_func_name)()) else: if max_invalid < np.inf: def aggregator(x): y = x.resample(source_freq).apply(sample_func) if y.isna().sum() < max_invalid: - agg_func(y) + return agg_func(y) else: return np.nan else: diff --git a/test/funcs/test_harm_funcs.py b/test/funcs/test_harm_funcs.py index 2419370e3..825f44265 100644 --- a/test/funcs/test_harm_funcs.py +++ b/test/funcs/test_harm_funcs.py @@ -18,7 +18,8 @@ from saqc.funcs.harm_functions import ( linear2Grid, interpolate2Grid, shift2Grid, - aggregate2Grid + aggregate2Grid, + aggregate ) @@ -334,20 +335,10 @@ def test_wrapper(data, flagger): field = data.columns[0] freq = '15min' flagger = flagger.initFlags(data) + aggregate(data, field, flagger, '15min', '30min', agg_func=np.sum, sample_func=np.mean) + linear2Grid(data, field, flagger, freq, flag_assignment_method='nearest_agg', flag_agg_func=max, drop_flags=None) aggregate2Grid(data, field, flagger, freq, agg_func=sum, agg_method='nearest_agg', flag_agg_func=max, drop_flags=None) shift2Grid(data, field, flagger, freq, shift_method='nearest_shift', drop_flags=None) - -if __name__ == "__main__": - dat = data() - flagger = TESTFLAGGER[1] - test_gridInterpolation(data(), 'polynomial') - flagger2 = TESTFLAGGER[2] - flagger = flagger.initFlags(dat) - flagger2 = flagger.initFlags(dat2) - dat_out, flagger = interpolate2Grid(dat, 'data', flagger, '15min', interpolation_method="polynomial", flag_assignment_method='nearest_agg', - flag_agg_func=max, drop_flags=None) - - print("stop") \ No newline at end of file -- GitLab