Skip to content

Commit

Permalink
refactor: fix some linting issues;
Browse files Browse the repository at this point in the history
  • Loading branch information
WenjieDu committed Jul 17, 2024
1 parent b153c2e commit 0e7be49
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pypots/imputation/lerp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

__all__ = [
"Lerp",
]
]
13 changes: 7 additions & 6 deletions pypots/imputation/lerp/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class Lerp(BaseImputer):
"""Linear interpolation (Lerp) imputation method.
Lerp will linearly interpolate missing values between the nearest non-missing values.
If there are missing values at the beginning or end of the series, they will be back-filled or forward-filled with the nearest non-missing value, respectively.
If there are missing values at the beginning or end of the series, they will be back-filled or
forward-filled with the nearest non-missing value, respectively.
If an entire series is empty, all 'nan' values will be filled with zeros.
"""

def __init__(
self,
):
Expand Down Expand Up @@ -95,14 +96,14 @@ def _interpolate_missing_values(X: np.ndarray):
X[nans] = np.interp(nan_index, index, X[~nans])
elif np.any(nans):
X[nans] = 0

if isinstance(X, np.ndarray):

trans_X = X.transpose((0, 2, 1))
n_samples, n_features, n_steps = trans_X.shape
reshaped_X = np.reshape(trans_X, (-1, n_steps))
imputed_X = np.ones(reshaped_X.shape)

for i, univariate_series in enumerate(reshaped_X):
t = np.copy(univariate_series)
_interpolate_missing_values(t)
Expand Down Expand Up @@ -133,7 +134,7 @@ def _interpolate_missing_values(X: np.ndarray):
"imputation": imputed_data,
}
return result_dict

def impute(
self,
test_set: Union[dict, str],
Expand All @@ -157,4 +158,4 @@ def impute(
"""

result_dict = self.predict(test_set, file_type=file_type)
return result_dict["imputation"]
return result_dict["imputation"]
2 changes: 1 addition & 1 deletion tests/imputation/lerp.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ def test_4_lazy_loading(self):


if __name__ == "__main__":
unittest.main()
unittest.main()

0 comments on commit 0e7be49

Please sign in to comment.