From 3ff8c89655fff16d4641e704bb1c5fe74e3e84e9 Mon Sep 17 00:00:00 2001
From: David Schaefer <david.schaefer@ufz.de>
Date: Wed, 5 Apr 2023 00:47:14 +0200
Subject: [PATCH] make resample write meta entries

---
 CHANGELOG.md                   |  1 +
 saqc/funcs/resampling.py       | 19 +++++++++++++++++++
 tests/funcs/test_resampling.py |  1 +
 3 files changed, 21 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 871d5797b..17ace3abf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
 ### Fixed
 - `func` arguments in text configurations were not parsed correctly
 - fail on duplicated arguments to test methods
+- `reample` was not writing meta entries
 
 ## [2.3.0](https://git.ufz.de/rdm-software/saqc/-/tags/v2.3.0) - 2023-01-17
 [List of commits](https://git.ufz.de/rdm-software/saqc/-/compare/v2.2.1...v2.3.0)
diff --git a/saqc/funcs/resampling.py b/saqc/funcs/resampling.py
index 52b2a5322..7ec5e4b86 100644
--- a/saqc/funcs/resampling.py
+++ b/saqc/funcs/resampling.py
@@ -15,6 +15,7 @@ import numpy as np
 import pandas as pd
 from typing_extensions import Literal
 
+from saqc.constants import UNFLAGGED
 from saqc.core import register
 from saqc.funcs.interpolation import _SUPPORTED_METHODS
 from saqc.lib.tools import evalFreqStr, filterKwargs, getFreqDelta, isflagged
@@ -238,6 +239,24 @@ class ResamplingMixin:
             func=aggregate2Freq,
             func_kws=kws,
         )
+        meta = {
+            "func": "resample",
+            "args": (),
+            "kwargs": {
+                "freq": freq,
+                "func": func,
+                "method": method,
+                "maxna": maxna,
+                "maxna_group": maxna_group,
+                "maxna_flags": maxna_flags,
+                "maxna_group_flags": maxna_group_flags,
+                "flag_func": flag_func,
+                "freq_check": freq_check,
+                **kwargs,
+            },
+        }
+        flagcol = pd.Series(UNFLAGGED, index=history.index)
+        history.append(flagcol, meta)
 
         self._data[field] = datcol
         self._flags.history[field] = history
diff --git a/tests/funcs/test_resampling.py b/tests/funcs/test_resampling.py
index 860ef654c..e945bd80d 100644
--- a/tests/funcs/test_resampling.py
+++ b/tests/funcs/test_resampling.py
@@ -113,6 +113,7 @@ def test_resampleAggregateInvert(data, method, freq, expected):
     qc = qc.resample(field_aggregated, freq, func=np.sum, method=method)
     assert qc._data[field_aggregated].index.freq == pd.Timedelta(freq)
     assert qc._data[field_aggregated].equals(expected)
+    assert qc._flags.history[field_aggregated].meta[-1]["func"] == "resample"
     checkInvariants(qc._data, qc._flags, field_aggregated, identical=True)
 
     qc = qc.concatFlags(field_aggregated, target=field, method="inverse_" + method)
-- 
GitLab