Skip to content

Commit

Permalink
Raise the proper error if picking columns fails
Browse files Browse the repository at this point in the history
  • Loading branch information
fraimondo committed Nov 27, 2024
1 parent 9411da8 commit 6384a65
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions julearn/transformers/dataframe/pick_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ColumnTypesLike,
JuTransformer,
)
from ...utils import logger
from ...utils import logger, raise_error
from ...utils.typing import DataLike


Expand Down Expand Up @@ -71,17 +71,19 @@ def _fit(
"""
self.support_mask_ = pd.Series(False, index=X.columns, dtype=bool)

try:
self.keep_columns_ = self.filter_columns(X).columns
to_keep = self.keep
if not isinstance(to_keep, list):
to_keep = [to_keep]
self.keep_columns_ = [
col for col in self.keep_columns_ if col in to_keep
]
self.support_mask_[self.keep_columns_] = True
except ValueError:
self.keep_columns_ = []
self.keep_columns_ = self.filter_columns(X).columns
to_keep = self.keep
if not isinstance(to_keep, list):
to_keep = [to_keep]
self.keep_columns_ = [
col for col in self.keep_columns_ if col in to_keep
]
if len(self.keep_columns_) != len(to_keep):
raise_error(
f"Kept columns do not match. Selected: ({self.keep}). "
f"Options are: {X.columns}"
)
self.support_mask_[self.keep_columns_] = True
self.support_mask_ = self.support_mask_.values
return self

Expand Down

0 comments on commit 6384a65

Please sign in to comment.