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

added support to roll with frequencie defined windows and center=True to customRolling

parent 08586229
No related branches found
No related tags found
3 merge requests!193Release 1.4,!188Release 1.4,!138WIP: Detect and reset offset
Pipeline #8392 passed with stage
in 6 minutes and 29 seconds
......@@ -1111,6 +1111,7 @@ def flagChangePoints(data, field, flagger, stat_func, thresh_func, bwd_window, m
indexer.win_points = np.array([True]*var_len)
indexer.window_size = int(pd.Timedelta(bwd_window).total_seconds() * 10 ** 9)
indexer.forward = False
indexer.center = False
bwd_start, bwd_end = indexer.get_window_bounds(var_len, min_periods_bwd, center, closed)
indexer.window_size = int(pd.Timedelta(fwd_window).total_seconds() * 10 ** 9)
......
......@@ -406,8 +406,14 @@ class FreqIndexer(BaseIndexer):
self.index_array[::i_dir])
if self.forward:
start, end = (num_values - end)[::-1], (num_values - start)[::-1]
end[~self.win_points] = 0
start[~self.win_points] = 0
if self.center:
end = (num_values - start)[::-1]
end = np.roll(end, -1)
end[-1] = num_values - 1
if self.win_points is not None:
end[~self.win_points] = 0
start[~self.win_points] = 0
return start, end
......@@ -426,8 +432,9 @@ class PeriodsIndexer(BaseIndexer):
end_s = np.arange(self.window_size, dtype="int64") + 1
end_e = start_e + self.window_size
end = np.concatenate([end_s, end_e])[:num_values]
start[~self.win_points] = 0
end[~self.win_points] = 0
if self.win_points is not None:
start[~self.win_points] = 0
end[~self.win_points] = 0
return start, end
......@@ -446,11 +453,12 @@ def customRolling(to_roll, winsz, func, roll_mask, min_periods=1, center=False,
func : Callable
Function to be rolled with. If the funcname matches a .rolling attribute,
the associated method of .rolling will be used instead of .apply(func) (=faster)
roll_mask : numpy.array[bool]
roll_mask : {numpy.array[bool], None}
A mask, indicating the rolling windows, `func` shall be applied on.
Has to be of same length as `to_roll`.
roll_mask[i] = False indicates, that the window with right end point to_roll.index[i] shall
be skipped.
Pass None if you want values to be masked.
min_periods : int, default 1
Gets passed on to the min_periods parameter of pandas.Rolling.
(Note, that rolling with freq string defined window size and `min_periods`=None,
......@@ -467,6 +475,9 @@ def customRolling(to_roll, winsz, func, roll_mask, min_periods=1, center=False,
forward : bool, default False
If true, roll with forward facing windows. (not yet implemented for
integer defined windows.)
center : bool, default False
If true, set the label to the center of the rolling window. Although available
for windows defined by sample rates! (yeah!)
Returns
-------
......
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