diff --git a/saqc/funcs/proc_functions.py b/saqc/funcs/proc_functions.py index 13097bbff7e8c9f9888c4adf8242672c895d6b40..071437ab0840a1517c4e4c9c827315e2c5658f87 100644 --- a/saqc/funcs/proc_functions.py +++ b/saqc/funcs/proc_functions.py @@ -12,6 +12,7 @@ from saqc.lib.tools import composeFunction, toSequence def proc_interpolateMissing(data, field, flagger, method, inter_order=2, inter_limit=2, interpol_flag='UNFLAGGED', downgrade_interpolation=False, return_chunk_bounds=False, not_interpol_flags=None, **kwargs): + data = data.copy() inter_data = interpolateNANs(data[field], method, order=inter_order, inter_limit=inter_limit, downgrade_interpolation=downgrade_interpolation, return_chunk_bounds=return_chunk_bounds) interpolated = data[field].isna() & inter_data.notna() diff --git a/saqc/lib/ts_operators.py b/saqc/lib/ts_operators.py index 331d65f2b4efcb54913216a47994faa28dab9b04..d72dcf93408d06f1ebe6b5f1a26dddd40efc8ef5 100644 --- a/saqc/lib/ts_operators.py +++ b/saqc/lib/ts_operators.py @@ -168,7 +168,7 @@ def interpolateNANs(data, method, order=2, inter_limit=2, downgrade_interpolatio :return: """ - data = pd.Series(data) + data = pd.Series(data).copy() gap_mask = (data.rolling(inter_limit, min_periods=0).apply(lambda x: np.sum(np.isnan(x)), raw=True)) != inter_limit if inter_limit == 2: @@ -190,7 +190,7 @@ def interpolateNANs(data, method, order=2, inter_limit=2, downgrade_interpolatio if method in ["linear", "time"]: - data.interpolate(method=method, inplace=True, limit=1, limit_area="inside") + data.interpolate(method=method, inplace=True, limit=inter_limit-1, limit_area="inside") else: dat_name = data.name @@ -221,7 +221,7 @@ def interpolateNANs(data, method, order=2, inter_limit=2, downgrade_interpolatio # squeezing the 1-dimensional frame resulting from groupby for consistency reasons data = data.squeeze(axis=1) data.name = dat_name - data = data.reindex(pre_index) + data = data.reindex(pre_index) if return_chunk_bounds: return data, chunk_bounds else: