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
8c8bba0d
Commit
8c8bba0d
authored
2 years ago
by
Peter Lünenschloß
Browse files
Options
Downloads
Patches
Plain Diff
black
parent
a1087b70
No related branches found
No related tags found
1 merge request
!600
Inter limit fix
Pipeline
#142277
failed with stages
in 4 minutes and 7 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
saqc/lib/ts_operators.py
+11
-7
11 additions, 7 deletions
saqc/lib/ts_operators.py
tests/lib/test_ts_operators.py
+2
-4
2 additions, 4 deletions
tests/lib/test_ts_operators.py
with
13 additions
and
11 deletions
saqc/lib/ts_operators.py
+
11
−
7
View file @
8c8bba0d
...
...
@@ -276,7 +276,7 @@ def meanQC(data, max_nan_total=np.inf, max_nan_consec=np.inf):
)
def
_interpolWrapper
(
x
,
order
=
2
,
method
=
'
time
'
,
downgrade_interpolation
=
False
):
def
_interpolWrapper
(
x
,
order
=
2
,
method
=
"
time
"
,
downgrade_interpolation
=
False
):
"""
Function that automatically modifies the interpolation level or returns uninterpolated
input data if the data configuration breaks the interpolation method at the selected degree.
...
...
@@ -300,6 +300,7 @@ def _interpolWrapper(x, order=2, method='time', downgrade_interpolation=False):
else
:
return
x
def
interpolateNANs
(
data
,
method
,
order
=
2
,
inter_limit
=
2
,
downgrade_interpolation
=
False
):
...
...
@@ -360,9 +361,7 @@ def interpolateNANs(
if
method
in
[
"
linear
"
,
"
time
"
]:
# in the case of linear interpolation, not much can go wrong/break so this conditional branch has efficient
# finish by just calling pandas interpolation routine to fill the gaps remaining in the data:
data
.
interpolate
(
method
=
method
,
inplace
=
True
,
limit_area
=
"
inside
"
)
data
.
interpolate
(
method
=
method
,
inplace
=
True
,
limit_area
=
"
inside
"
)
else
:
# if the method that is interpolated with depends on not only the left and right border points of any gap,
...
...
@@ -370,9 +369,14 @@ def interpolateNANs(
# So we use the gap_mask to group the data into chunks and perform the interpolation on every chunk seperatly
# with the .transform method of the grouper.
gap_mask
=
(
~
gap_mask
).
cumsum
()[
data
.
index
]
data
=
data
.
groupby
(
by
=
gap_mask
).
transform
(
_interpolWrapper
,
**
{
'
order
'
:
order
,
'
method
'
:
method
,
'
downgrade_inerpolation
'
:
downgrade_interpolation
})
data
=
data
.
groupby
(
by
=
gap_mask
).
transform
(
_interpolWrapper
,
**
{
"
order
"
:
order
,
"
method
"
:
method
,
"
downgrade_inerpolation
"
:
downgrade_interpolation
,
},
)
# finally reinsert the dropped data gaps
data
=
data
.
reindex
(
pre_index
)
return
data
...
...
This diff is collapsed.
Click to expand it.
tests/lib/test_ts_operators.py
+
2
−
4
View file @
8c8bba0d
...
...
@@ -228,10 +228,8 @@ def test_rateOfChange(data, expected):
],
)
def
test_interpolatNANs
(
limit
,
data
,
expected
):
got
=
interpolateNANs
(
pd
.
Series
(
data
),
inter_limit
=
limit
,
method
=
'
linear
'
)
got
=
interpolateNANs
(
pd
.
Series
(
data
),
inter_limit
=
limit
,
method
=
"
linear
"
)
try
:
assert
got
.
equals
(
pd
.
Series
(
expected
,
dtype
=
float
))
except
:
print
(
'
stop
'
)
\ No newline at end of file
print
(
"
stop
"
)
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