Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SaQC
Manage
Activity
Members
Labels
Plan
Issues
36
Issue boards
Milestones
Wiki
Code
Merge requests
8
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
rdm-software
SaQC
Commits
d9636c53
Commit
d9636c53
authored
11 months ago
by
Peter Lünenschloß
Browse files
Options
Downloads
Patches
Plain Diff
fixed tests
parent
ebd1dc6c
No related branches found
No related tags found
1 merge request
!850
Horizontal axis rolling
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
saqc/funcs/rolling.py
+19
-10
19 additions, 10 deletions
saqc/funcs/rolling.py
tests/funcs/test_proc_functions.py
+21
-0
21 additions, 0 deletions
tests/funcs/test_proc_functions.py
with
40 additions
and
10 deletions
saqc/funcs/rolling.py
+
19
−
10
View file @
d9636c53
...
...
@@ -42,7 +42,9 @@ class RollingMixin:
"""
Calculate a rolling-window function on the data.
Note, that the data gets assigned the worst flag present in the original data.
Note, that the new data gets assigned the worst flag present in the window it was aggregated from.
Note, That you also can select multiple fields to get a rolling calculation over those.
Parameters
----------
...
...
@@ -178,9 +180,24 @@ def _hroll(
center
:
bool
=
True
,
**
kwargs
,
):
if
isinstance
(
window
,
str
):
freq
=
getFreqDelta
(
data
[
field
].
to_pandas
().
index
)
if
freq
is
None
:
raise
ValueError
(
f
"
Rolling over more than one column is only supported if either the data has a unitary
"
f
'
sampling rate, or window is an Integer.
"
{
window
}
"
was passed and combined
{
field
}
'
f
"
index is not unitarily sampled
"
)
else
:
window
=
int
(
np
.
floor
(
pd
.
Timedelta
(
window
)
/
freq
))
views
=
np
.
lib
.
stride_tricks
.
sliding_window_view
(
data
[
field
].
to_pandas
(),
(
window
,
len
(
field
))
)
f_views
=
np
.
lib
.
stride_tricks
.
sliding_window_view
(
pd
.
DataFrame
({
f
:
flags
[
f
]
for
f
in
field
}),
(
window
,
len
(
field
))
)
frame
=
pd
.
DataFrame
(
views
.
reshape
(
views
.
shape
[
0
],
views
.
shape
[
1
]
*
views
.
shape
[
2
]
*
views
.
shape
[
3
])
)
...
...
@@ -191,20 +208,12 @@ def _hroll(
insuff_periods_mask
=
~
(
~
frame
.
isna
()).
sum
(
axis
=
1
)
>=
min_periods
result
[
insuff_periods_mask
]
=
np
.
nan
out
=
pd
.
Series
(
np
.
nan
,
index
=
data
[
field
].
to_pandas
().
index
)
out
[
window
-
1
:]
=
result
if
center
:
out
=
out
.
shift
(
-
window
//
2
)
f_views
=
np
.
lib
.
stride_tricks
.
sliding_window_view
(
pd
.
DataFrame
({
f
:
flags
[
f
]
for
f
in
field
}),
(
window
,
len
(
field
))
)
f_result
=
f_views
.
max
(
axis
=
(
2
,
3
)).
squeeze
()
d_out
=
pd
.
Series
(
np
.
nan
,
index
=
data
[
field
].
to_pandas
().
index
)
d_out
[
window
-
1
:]
=
result
if
center
:
d_out
=
d_out
.
shift
(
-
window
/
/
2
)
d_out
=
d_out
.
shift
(
-
int
(
np
.
floor
(
window
/
2
)
))
f_out
=
pd
.
Series
(
np
.
nan
,
index
=
data
[
field
].
to_pandas
().
index
)
f_out
[
window
-
1
:]
=
f_result
...
...
This diff is collapsed.
Click to expand it.
tests/funcs/test_proc_functions.py
+
21
−
0
View file @
d9636c53
...
...
@@ -20,6 +20,27 @@ from saqc.lib.ts_operators import linearInterpolation, polynomialInterpolation
from
tests.fixtures
import
char_dict
,
course_3
,
course_5
# noqa, todo: fix fixtures
@pytest.mark.parametrize
(
(
"
window
"
,
"
center
"
,
"
expected
"
),
[
(
1
,
True
,
[
3
,
2
,
3
,
2
]),
(
2
,
False
,
[
np
.
nan
,
5
,
5
,
5
]),
(
3
,
True
,
[
np
.
nan
,
8
,
7
,
np
.
nan
]),
(
"
20min
"
,
True
,
[
5
,
5
,
5
,
np
.
nan
]),
],
)
def
test_multivariateRolling
(
window
,
center
,
expected
):
data
=
pd
.
DataFrame
(
{
"
a
"
:
[
1
,
np
.
nan
,
3
,
4
],
"
b
"
:
[
1
,
2
,
3
,
4
],
"
c
"
:
[
1
,
2
,
3
,
np
.
nan
]},
index
=
pd
.
date_range
(
"
2000
"
,
periods
=
4
,
freq
=
"
10min
"
),
)
qc
=
saqc
.
SaQC
(
data
)
qc
=
qc
.
rolling
(
[
"
a
"
,
"
b
"
,
"
c
"
],
func
=
"
count
"
,
target
=
"
count
"
,
window
=
window
,
center
=
center
)
assert
np
.
array_equal
(
qc
.
data
[
"
count
"
].
values
,
expected
,
equal_nan
=
True
)
def
test_rollingInterpolateMissing
(
course_5
):
data
,
characteristics
=
course_5
(
periods
=
10
,
nan_slice
=
[
5
,
6
])
field
=
data
.
columns
[
0
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment