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

black

parent a1087b70
No related branches found
No related tags found
1 merge request!600Inter limit fix
Pipeline #142277 failed with stages
in 4 minutes and 7 seconds
...@@ -276,7 +276,7 @@ def meanQC(data, max_nan_total=np.inf, max_nan_consec=np.inf): ...@@ -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 Function that automatically modifies the interpolation level or returns uninterpolated
input data if the data configuration breaks the interpolation method at the selected degree. 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): ...@@ -300,6 +300,7 @@ def _interpolWrapper(x, order=2, method='time', downgrade_interpolation=False):
else: else:
return x return x
def interpolateNANs( def interpolateNANs(
data, method, order=2, inter_limit=2, downgrade_interpolation=False data, method, order=2, inter_limit=2, downgrade_interpolation=False
): ):
...@@ -360,9 +361,7 @@ def interpolateNANs( ...@@ -360,9 +361,7 @@ def interpolateNANs(
if method in ["linear", "time"]: if method in ["linear", "time"]:
# in the case of linear interpolation, not much can go wrong/break so this conditional branch has efficient # 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: # finish by just calling pandas interpolation routine to fill the gaps remaining in the data:
data.interpolate( data.interpolate(method=method, inplace=True, limit_area="inside")
method=method, inplace=True, limit_area="inside"
)
else: else:
# if the method that is interpolated with depends on not only the left and right border points of any gap, # 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( ...@@ -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 # 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. # with the .transform method of the grouper.
gap_mask = (~gap_mask).cumsum()[data.index] gap_mask = (~gap_mask).cumsum()[data.index]
data = data.groupby(by=gap_mask).transform(_interpolWrapper, **{'order':order, data = data.groupby(by=gap_mask).transform(
'method':method, _interpolWrapper,
'downgrade_inerpolation':downgrade_interpolation}) **{
"order": order,
"method": method,
"downgrade_inerpolation": downgrade_interpolation,
},
)
# finally reinsert the dropped data gaps # finally reinsert the dropped data gaps
data = data.reindex(pre_index) data = data.reindex(pre_index)
return data return data
......
...@@ -228,10 +228,8 @@ def test_rateOfChange(data, expected): ...@@ -228,10 +228,8 @@ def test_rateOfChange(data, expected):
], ],
) )
def test_interpolatNANs(limit, data, expected): def test_interpolatNANs(limit, data, expected):
got = interpolateNANs( got = interpolateNANs(pd.Series(data), inter_limit=limit, method="linear")
pd.Series(data), inter_limit=limit, method='linear'
)
try: try:
assert got.equals(pd.Series(expected, dtype=float)) assert got.equals(pd.Series(expected, dtype=float))
except: except:
print('stop') print("stop")
\ No newline at end of file
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