Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jwdink committed Nov 16, 2023
2 parents a8850ea + fe97969 commit a4bb55e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion foundry/preprocessing/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ToCategorical(TransformerMixin, BaseEstimator):
def __init__(self):
self.categories_ = None

def get_feature_names_out(self, feature_names_in) -> Sequence[str]:
def get_feature_names_out(self, feature_names_in=None) -> Sequence[str]:
return self._feature_names_out

def fit(self, X: pd.DataFrame, y=None) -> 'ToCategorical':
Expand Down
2 changes: 1 addition & 1 deletion foundry/preprocessing/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def fit(self, X, y=None) -> 'FourierFeatures':

return self

def get_feature_names_out(self, feature_names_in) -> np.ndarray:
def get_feature_names_out(self, feature_names_in=None) -> np.ndarray:
feature_names_in = _check_feature_names_in(self, feature_names_in)

if len(feature_names_in) == 1:
Expand Down
8 changes: 5 additions & 3 deletions foundry/preprocessing/sklearn/backports.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from sklearn.utils.validation import _check_feature_names_in


# TODO: use sklearn versions if on newer version that implements `get_feature_names_out`

class FunctionTransformer(FunctionTransformerBase):
"""
Add ``get_feature_names_out()`` to ``FunctionTransformer``
Expand All @@ -32,7 +34,7 @@ def fit(self, X, y=None) -> 'FunctionTransformer':
self._feature_names_out = [f'x{i}' for i in range(maybe_df.shape[1])]
return self

def get_feature_names_out(self, feature_names_in) -> Sequence[str]:
def get_feature_names_out(self, feature_names_in=None) -> Sequence[str]:
if len(feature_names_in) == len(self._feature_names_out):
return np.asarray([
x if x == y else f'{x}_{y}' for x, y in zip(feature_names_in, self._feature_names_out)
Expand All @@ -46,8 +48,8 @@ def get_feature_names_out(self, feature_names_in) -> Sequence[str]:


class SimpleImputer(SimpleImputerBase):
def get_feature_names_out(self, input_features=None):
input_features = _check_feature_names_in(self, input_features)
def get_feature_names_out(self, feature_names_in=None):
input_features = _check_feature_names_in(self, feature_names_in)
names = input_features[~isna(self.statistics_)]
if not self.add_indicator:
return names
Expand Down
2 changes: 1 addition & 1 deletion foundry/preprocessing/sklearn/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def transform(self, X: pd.DataFrame, y=None) -> pd.DataFrame:

return X.drop(columns=X.columns[X.columns.isin(new_cols)]).join(df_new_cols)

def get_feature_names_out(self):
def get_feature_names_out(self, feature_names_in=None):
if self.feature_names_in_ is None:
raise NotFittedError(f"This {type(self).__name__} is not fitted. Cannot get_feature_names_out.")

Expand Down

0 comments on commit a4bb55e

Please sign in to comment.