Skip to content
Snippets Groups Projects

Several fixes and refactorings to the interpolation methods

Closed David Schäfer requested to merge interpolation_fixes into develop
2 unresolved threads
Files
2
# SPDX-FileCopyrightText: 2021 Helmholtz-Zentrum für Umweltforschung GmbH - UFZ
#
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import annotations
import numpy as np
import pandas as pd
import pytest
from numpy.testing import assert_array_equal, assert_equal
from pandas.testing import assert_series_equal
import saqc.lib.ts_operators as tsops
from saqc.lib.ts_operators import interpolateNANs
def test_butterFilter():
@@ -193,3 +195,72 @@ def test_rateOfChange(data, expected):
result = rateOfChange(data)
assert_series_equal(result, expected, check_names=False)
@pytest.mark.parametrize(
"limit,area,direction,data,expected",
[
(
1,
"inside",
None,
[np.nan, 0, np.nan, np.nan, np.nan, 4, np.nan],
[np.nan, 0, np.nan, np.nan, np.nan, 4, np.nan],
),
(
2,
"inside",
None,
[np.nan, 0, np.nan, np.nan, np.nan, 4, np.nan],
[np.nan, 0, np.nan, np.nan, np.nan, 4, np.nan],
),
(
3,
"inside",
None,
[np.nan, 0, np.nan, np.nan, np.nan, 4, np.nan],
[np.nan, 0, 1, 2, 3, 4, np.nan],
),
(
None,
"inside",
None,
[np.nan, 0, np.nan, np.nan, np.nan, 4, np.nan],
[np.nan, 0, 1, 2, 3, 4, np.nan],
),
(
None,
"outside",
"forward",
[np.nan, 0, np.nan, np.nan, np.nan, 4, np.nan],
[np.nan, 0, np.nan, np.nan, np.nan, 4, 4],
),
(
None,
"outside",
"backward",
[np.nan, 0, np.nan, np.nan, np.nan, 4, np.nan],
[0, 0, np.nan, np.nan, np.nan, 4, np.nan],
),
(
None,
"outside",
"both",
[np.nan, 0, np.nan, np.nan, np.nan, 4, np.nan],
[0, 0, np.nan, np.nan, np.nan, 4, 4],
),
(
None,
None,
"both",
[np.nan, 0, np.nan, np.nan, np.nan, 4, np.nan],
[0, 0, 1, 2, 3, 4, 4],
),
],
)
def test_interpolatNANs(limit, area, direction, data, expected):
got = interpolateNANs(
pd.Series(data), limit=limit, limit_area=area, limit_direction=direction
)
assert got.equals(pd.Series(expected, dtype=float))
Please register or sign in to reply
Loading