-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -614,3 +614,35 @@ def _raise_exception_for_negative_values(column: pd.Series): | |
"\tLog-based metrics are not supported for negative target values.\n" | ||
f"\tCheck '{column.name}' at rows {str(negative_item_indices)}." | ||
) | ||
|
||
def common_nan_removal(data: pd.DataFrame, selected_columns: List[str]) -> Tuple[List[pd.Series], bool]: | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nnansters
Contributor
|
||
"""Remove NaN values from rows of selected columns. | ||
Parameters | ||
---------- | ||
data: pd.DataFrame | ||
Pandas dataframe containing data. | ||
selected_columns: List[str] | ||
List containing the strings of column names | ||
Returns | ||
------- | ||
col_list: | ||
List containing the clean columns specified. Order of columns from selected_columns is | ||
preserved. | ||
empty: | ||
Boolean whether the resulting data are contain any rows (false) or not (true) | ||
""" | ||
# If we want target and it's not available we get None | ||
if not set(selected_columns) <= set(data.columns): | ||
raise InvalidArgumentsException( | ||
f"Selected columns: {selected_columns} not all present in provided data columns {list(data.columns)}" | ||
) | ||
df = data[selected_columns].dropna(axis=0, how='any', inplace=False).reset_index() | ||
empty: bool = False | ||
if df.shape[0] == 0: | ||
empty = True | ||
results = [] | ||
for el in selected_columns: | ||
results.append(df[el]) | ||
return (results, empty) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Functionality seems to largely overlap with
_remove_nans
. Maybe we could just use that function?As far as I can tell the extra stuff this function provides (checking for column presence & empty) isn't even used.