Skip to content
Snippets Groups Projects
Commit 1f3cc3a6 authored by Peter Lünenschloß's avatar Peter Lünenschloß
Browse files

resample signature cleanup

parent 3cbbfdb0
No related branches found
No related tags found
3 merge requests!685Release 2.4,!684Release 2.4,!664resample signature cleanup
......@@ -16,9 +16,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
- Deprecate `interpolate`, `linear` and `shift` in favor of `align`
- Depreacte `roll` in favor of `rolling`
- Rename `interplateInvalid` to `interpolate`
- Rename `interpolateIndex` to `align`
- Rename `interpolateIndex` to `align`
### Removed
- Parameter `limit` from `align`
- Parameter `max_na_group_flags`, `max_na_flags`, `flag_func`, `freq_check` removed from `resample`
### Fixed
- `func` arguments in text configurations were not parsed correctly
- fail on duplicated arguments to test methods
......
......@@ -18,7 +18,7 @@ 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
from saqc.lib.tools import filterKwargs, getFreqDelta, isflagged
from saqc.lib.ts_operators import aggregate2Freq, shift2Freq
if TYPE_CHECKING:
......@@ -78,7 +78,6 @@ class ResamplingMixin:
field: str,
freq: str,
method: Literal["fshift", "bshift", "nshift"] = "nshift",
freq_check: Optional[Literal["check", "auto"]] = None,
**kwargs,
) -> "SaQC":
"""
......@@ -99,11 +98,6 @@ class ResamplingMixin:
* 'bshift' : shift grid points to the first succeeding time stamp (if any)
* 'fshift' : shift grid points to the last preceeding time stamp (if any)
freq_check : {None, 'check', 'auto'}, default None
* ``None`` : do not validate the ``freq`` string.
* 'check' : check ``freq`` against an frequency estimation, produces a warning in case of miss matches.
* 'auto' : estimate frequency, `freq` is ignored.
Returns
-------
saqc.SaQC
......@@ -116,7 +110,7 @@ class ResamplingMixin:
""",
DeprecationWarning,
)
freq = evalFreqStr(freq, freq_check, self._data[field].index)
return self.align(field=field, freq=freq, method=method, **kwargs)
@register(mask=["field"], demask=[], squeeze=[])
......@@ -128,10 +122,6 @@ class ResamplingMixin:
method: Literal["fagg", "bagg", "nagg"] = "bagg",
maxna: Optional[int] = None,
maxna_group: Optional[int] = None,
maxna_flags: Optional[int] = None, # TODO: still a case ??
maxna_group_flags: Optional[int] = None,
flag_func: Callable[[pd.Series], float] = max,
freq_check: Optional[Literal["check", "auto"]] = None,
**kwargs,
) -> "SaQC":
"""
......@@ -180,28 +170,6 @@ class ResamplingMixin:
maxna_group : {None, int}, default None
Same as `maxna` but for consecutive NaNs.
maxna_flags : {None, int}, default None
Same as `max_invalid`, only applying for the flags. The flag regarded
as "invalid" value, is the one passed to empty_intervals_flag (
default=``BAD``). Also this is the flag assigned to invalid/empty intervals.
maxna_group_flags : {None, int}, default None
Same as `maxna_flags`, only applying onto flags. The flag regarded as
"invalid" value, is the one passed to empty_intervals_flag. Also this is the
flag assigned to invalid/empty intervals.
flag_func : Callable, default: max
The function you want to aggregate the flags with. It should be capable of
operating on the flags dtype (usually ordered categorical).
freq_check : {None, 'check', 'auto'}, default None
* ``None``: do not validate frequency-string passed to `freq`
* ``'check'``: estimate frequency and log a warning if estimate miss matchs
frequency string passed to 'freq', or if no uniform sampling rate could be
estimated
* ``'auto'``: estimate frequency and use estimate. (Ignores `freq` parameter.)
Returns
-------
saqc.SaQC
......@@ -213,8 +181,6 @@ class ResamplingMixin:
# see for #GL-374
datcol = pd.Series(index=pd.DatetimeIndex([]), dtype=datcol.dtype)
freq = evalFreqStr(freq, freq_check, datcol.index)
datcol = aggregate2Freq(
datcol,
method,
......@@ -228,10 +194,10 @@ class ResamplingMixin:
kws = dict(
method=method,
freq=freq,
agg_func=flag_func,
agg_func=max,
fill_value=np.nan,
max_invalid_total=maxna_flags,
max_invalid_consec=maxna_group_flags,
max_invalid_total=maxna,
max_invalid_consec=maxna_group,
)
history = self._flags.history[field].apply(
......@@ -248,10 +214,6 @@ class ResamplingMixin:
"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,
},
}
......
......@@ -292,38 +292,6 @@ def estimateFrequency(
return str(int(gcd_freq)) + "min", [str(int(i)) + "min" for i in freqs]
def evalFreqStr(freq, check, index):
if check in ["check", "auto"]:
f_passed = freq
freq = index.inferred_freq
freqs = [freq]
if freq is None:
freq, freqs = estimateFrequency(index)
if freq is None:
warnings.warn("Sampling rate could not be estimated.")
if len(freqs) > 1:
warnings.warn(
f"Sampling rate seems to be not uniform!." f"Detected: {freqs}"
)
if check == "check":
f_passed_seconds = pd.Timedelta(f_passed).total_seconds()
freq_seconds = pd.Timedelta(freq).total_seconds()
if f_passed_seconds != freq_seconds:
warnings.warn(
f"Sampling rate estimate ({freq}) missmatches passed frequency ({f_passed})."
)
elif check == "auto":
if freq is None:
raise ValueError(
"Frequency estimation for non-empty series failed with no fall back frequency passed."
)
f_passed = freq
else:
f_passed = freq
return f_passed
def detectDeviants(
data,
metric,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment