Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Bugfixes
(not into their subclasses). If you need the items evaluated (ie if they
contain DataOps or Choices), store them in one of the builtin collections.
:pr:`1612` by :user:`Jérôme Dockès <jeromedockes>`.

- Fixed a bug that happened when ``get_feature_names_out`` was called on instances
of the :class:`DatetimeEncoder`. :pr:`1622` by :user:`Riccardo Cappuzzo<rcap107>`.

Release 0.6.1
===================
Expand Down
20 changes: 19 additions & 1 deletion skrub/_datetime_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def transform(self, column):
transformed : DataFrame
The extracted features.
"""
check_is_fitted(self, "extracted_features_")
check_is_fitted(self, "all_outputs_")
name = sbd.name(column)

# Checking again which values are null if calling only transform
Expand All @@ -460,6 +460,8 @@ def transform(self, column):
X_out = sbd.copy_index(column, sbd.make_dataframe_like(column, all_extracted))
X_out = sbd.concat(X_out, *new_features, axis=1)

self.all_outputs_ = sbd.column_names(X_out)

# Censoring all the null features
X_out = sbd.where_row(X_out, not_nulls, null_mask)

Expand Down Expand Up @@ -492,6 +494,22 @@ def __sklearn_tags__(self):
tags.transformer_tags = TransformerTags(preserves_dtype=[])
return tags

def get_feature_names_out(self, input_features=None):
"""Get output feature names for transformation.

Parameters
----------
input_features : array-like of str or None, default=None
Ignored.

Returns
-------
feature_names_out : ndarray of str objects
Transformed feature names.
"""
check_is_fitted(self, "all_outputs_")
return self.all_outputs_


class _SplineEncoder(SingleColumnTransformer):
"""Generate univariate B-spline bases for features.
Expand Down
1 change: 1 addition & 0 deletions skrub/tests/test_datetime_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ def test_all_outputs_choice(datetime_cols, params, all_outputs):
enc = DatetimeEncoder(**params)
res = enc.fit_transform(datetime_cols.datetime)
assert enc.all_outputs_ == [f"when_{f}" for f in all_outputs]
assert enc.get_feature_names_out() == [f"when_{f}" for f in all_outputs]
assert sbd.column_names(res) == [f"{f}" for f in enc.all_outputs_]


Expand Down
Loading