Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SaQC
Manage
Activity
Members
Labels
Plan
Issues
35
Issue boards
Milestones
Wiki
Code
Merge requests
7
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
119875ce
Commit
119875ce
authored
2 years ago
by
Bert Palm
🎇
Browse files
Options
Downloads
Patches
Plain Diff
refactored _maxConsecutiveNan and added test.
parent
ec62df83
No related branches found
Branches containing commit
No related tags found
1 merge request
!462
More tests
Pipeline
#93416
passed with stage
in 2 minutes and 4 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
saqc/lib/ts_operators.py
+26
-18
26 additions, 18 deletions
saqc/lib/ts_operators.py
tests/lib/test_ts_operators.py
+33
-4
33 additions, 4 deletions
tests/lib/test_ts_operators.py
with
59 additions
and
22 deletions
saqc/lib/ts_operators.py
+
26
−
18
View file @
119875ce
...
...
@@ -139,9 +139,22 @@ def maxGap(in_arr):
@nb.njit
def
_maxConsecutiveNan
(
arr
,
max_consec
):
# checks if arr (boolean array) has not more then "max_consec" consecutive True
# values
def
_exceedConsecutiveNanLimit
(
arr
,
max_consec
):
"""
Check if array has more consecutive NaNs than allowed.
Parameters
----------
arr : bool array
boolean array
max_consec : int
maximum allowed consecutive `True`s
Returns
-------
exceeded: bool
True if more than allowed consecutive NaNs appear, False otherwise.
"""
current
=
0
idx
=
0
while
idx
<
arr
.
size
:
...
...
@@ -149,10 +162,10 @@ def _maxConsecutiveNan(arr, max_consec):
current
+=
1
idx
+=
1
if
current
>
max_consec
:
return
Fals
e
return
Tru
e
current
=
0
idx
+=
1
return
Tru
e
return
Fals
e
def
validationTrafo
(
data
,
max_nan_total
,
max_nan_consec
):
...
...
@@ -160,22 +173,17 @@ def validationTrafo(data, max_nan_total, max_nan_consec):
# True-array of input array size for invalid input arrays False array for valid
# ones
data
=
data
.
copy
()
if
(
max_nan_total
is
np
.
inf
)
&
(
max_nan_consec
is
np
.
inf
)
:
if
max_nan_total
is
np
.
inf
and
max_nan_consec
is
np
.
inf
:
return
data
# nan_mask = np.isnan(data)
if
data
.
sum
()
<=
max_nan_total
:
if
max_nan_consec
is
np
.
inf
:
data
[:]
=
False
return
data
elif
_maxConsecutiveNan
(
np
.
asarray
(
data
),
max_nan_consec
):
data
[:]
=
False
else
:
data
[:]
=
True
if
data
.
sum
()
>
max_nan_total
:
value
=
True
elif
max_nan_consec
is
np
.
inf
:
value
=
False
else
:
data
[:]
=
True
value
=
_exceedConsecutiveNanLimit
(
np
.
asarray
(
data
),
max_nan_consec
)
data
[:]
=
value
return
data
...
...
@@ -257,7 +265,7 @@ def interpolateNANs(
except
(
NotImplementedError
,
ValueError
):
warnings
.
warn
(
f
"
Interpolation with method
{
method
}
is not supported at order
"
f
"
{
wrap_order
}
. and will be performed at order
{
wrap_order
-
1
}
"
f
"
{
wrap_order
}
. and will be performed at order
{
wrap_order
-
1
}
"
)
return
_interpolWrapper
(
x
,
int
(
wrap_order
-
1
),
wrap_method
)
elif
x
.
size
<
3
:
...
...
This diff is collapsed.
Click to expand it.
tests/lib/test_ts_operators.py
+
33
−
4
View file @
119875ce
# SPDX-FileCopyrightText: 2021 Helmholtz-Zentrum für Umweltforschung GmbH - UFZ
#
# SPDX-License-Identifier: GPL-3.0-or-later
import
numpy
as
np
import
pytest
import
saqc.lib.ts_operators
as
tsops
...
...
@@ -10,9 +10,38 @@ import pandas as pd
def
test_butterFilter
():
assert
(
tsops
.
butterFilter
(
pd
.
Series
([
1
,
-
1
]
*
100
),
cutoff
=
0.1
)
-
pd
.
Series
([
1
,
-
1
]
*
100
)
tsops
.
butterFilter
(
pd
.
Series
([
1
,
-
1
]
*
100
),
cutoff
=
0.1
)
-
pd
.
Series
([
1
,
-
1
]
*
100
)
).
mean
()
<
0.5
def
test_identity
():
assert
tsops
.
identity
(
99
)
==
99
T
=
True
F
=
False
@pytest.mark.parametrize
(
"
arr,maxc,expected
"
,
[
(
np
.
array
([]),
1
,
False
),
(
np
.
array
([
F
]),
1
,
False
),
(
np
.
array
([
F
,
F
,
F
]),
1
,
False
),
#
(
np
.
array
([
T
]),
0
,
True
),
(
np
.
array
([
T
]),
1
,
False
),
#
(
np
.
array
([
F
,
T
,
F
]),
0
,
True
),
(
np
.
array
([
F
,
T
,
F
]),
1
,
False
),
#
(
np
.
array
([
F
,
T
,
T
,
T
,
T
,
F
]),
0
,
True
),
(
np
.
array
([
F
,
T
,
T
,
T
,
T
,
F
]),
1
,
True
),
(
np
.
array
([
F
,
T
,
T
,
T
,
T
,
F
]),
2
,
True
),
(
np
.
array
([
F
,
T
,
T
,
T
,
T
,
F
]),
3
,
True
),
(
np
.
array
([
F
,
T
,
T
,
T
,
T
,
F
]),
4
,
False
),
(
np
.
array
([
F
,
T
,
T
,
T
,
T
,
F
]),
5
,
False
),
#
(
np
.
array
([
F
,
T
,
T
,
F
,
T
,
T
,
F
]),
2
,
False
),
],
)
def
test__maxConsecutiveNan
(
arr
,
maxc
,
expected
):
result
=
tsops
.
_exceedConsecutiveNanLimit
(
arr
,
maxc
)
assert
result
is
expected
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