-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dropna #178
dropna #178
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -209,13 +209,16 @@ def __init__( # noqa: PLR0913 | |||||
self._trend: dict | ||||||
self._is_fit = False | ||||||
|
||||||
def fit(self, data: Union[xr.DataArray, xr.Dataset]) -> None: | ||||||
def fit(self, data: Union[xr.DataArray, xr.Dataset], dropna=False) -> None: | ||||||
"""Fit this Preprocessor to input data. | ||||||
|
||||||
Args: | ||||||
data: Input data for fitting. | ||||||
dropna: If True, drop all NaN values from the data before preprocessing. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Point out that this |
||||||
""" | ||||||
_check_input_data(data) | ||||||
if dropna: | ||||||
data = data.dropna("time") | ||||||
if self._window_size not in [None, 1]: | ||||||
data_rolling = data.rolling( | ||||||
dim={"time": self._window_size}, # type: ignore | ||||||
|
@@ -228,7 +231,6 @@ def fit(self, data: Union[xr.DataArray, xr.Dataset]) -> None: | |||||
|
||||||
if self._subtract_climatology: | ||||||
self._climatology = _get_climatology(data_rolling, self._timescale) | ||||||
|
||||||
if self._detrend is not None: | ||||||
if self._subtract_climatology: | ||||||
deseasonalized = _subtract_climatology( | ||||||
|
@@ -241,16 +243,20 @@ def fit(self, data: Union[xr.DataArray, xr.Dataset]) -> None: | |||||
self._is_fit = True | ||||||
|
||||||
def transform( | ||||||
self, data: Union[xr.DataArray, xr.Dataset] | ||||||
self, data: Union[xr.DataArray, xr.Dataset], dropna=False | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
) -> Union[xr.DataArray, xr.Dataset]: | ||||||
"""Apply the preprocessing steps to the input data. | ||||||
|
||||||
Args: | ||||||
data: Input data to perform preprocessing. | ||||||
dropna: If True, drop all NaN values from the data before preprocessing. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
Returns: | ||||||
Preprocessed data. | ||||||
""" | ||||||
if dropna: | ||||||
data = data.dropna("time") | ||||||
|
||||||
if not self._is_fit: | ||||||
raise ValueError( | ||||||
"The preprocessor has to be fit to data before a transform" | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add a type here to please mypy.