Skip to content
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

Adds drop column transformer component #827

Merged
merged 13 commits into from
Jun 4, 2020
10 changes: 6 additions & 4 deletions evalml/pipelines/components/transformers/drop_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ def fit(self, X, y=None):
cols = self.parameters["columns"] or []
if not isinstance(X, pd.DataFrame):
X = pd.DataFrame(X)
if not set(cols).issubset(X.columns):
raise ValueError("Columns {} not found in input data".format(', '.join(f"'{col_name}'" for col_name in list(set(cols) - set(X.columns)))))
missing_cols = set(cols) - set(X.columns)
angela97lin marked this conversation as resolved.
Show resolved Hide resolved
if len(missing_cols) > 0:
raise ValueError("Columns {} not found in input data".format(', '.join(f"'{col_name}'" for col_name in missing_cols)))
return self

def transform(self, X, y=None):
Expand All @@ -39,6 +40,7 @@ def transform(self, X, y=None):
cols = self.parameters["columns"] or []
if not isinstance(X, pd.DataFrame):
X = pd.DataFrame(X)
if not set(cols).issubset(X.columns):
raise ValueError("Column(s) {} not found in input data".format(', '.join(f"'{col_name}'" for col_name in list(set(cols) - set(X.columns)))))
missing_cols = set(cols) - set(X.columns)
if len(missing_cols) > 0:
raise ValueError("Columns {} not found in input data".format(', '.join(f"'{col_name}'" for col_name in missing_cols)))
return X.drop(columns=cols, axis=1)