Skip to content

Commit 4a86b67

Browse files
authored
FIX - fixing get_feature_names_out in DatetimeEncoder (#1622)
1 parent 13bcc48 commit 4a86b67

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

CHANGES.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ Bugfixes
5050
(not into their subclasses). If you need the items evaluated (ie if they
5151
contain DataOps or Choices), store them in one of the builtin collections.
5252
:pr:`1612` by :user:`Jérôme Dockès <jeromedockes>`.
53-
53+
- Fixed a bug that happened when ``get_feature_names_out`` was called on instances
54+
of the :class:`DatetimeEncoder`. :pr:`1622` by :user:`Riccardo Cappuzzo<rcap107>`.
5455

5556
Release 0.6.1
5657
===================

skrub/_datetime_encoder.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def transform(self, column):
434434
transformed : DataFrame
435435
The extracted features.
436436
"""
437-
check_is_fitted(self, "extracted_features_")
437+
check_is_fitted(self, "all_outputs_")
438438
name = sbd.name(column)
439439

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

463+
self.all_outputs_ = sbd.column_names(X_out)
464+
463465
# Censoring all the null features
464466
X_out = sbd.where_row(X_out, not_nulls, null_mask)
465467

@@ -492,6 +494,22 @@ def __sklearn_tags__(self):
492494
tags.transformer_tags = TransformerTags(preserves_dtype=[])
493495
return tags
494496

497+
def get_feature_names_out(self, input_features=None):
498+
"""Get output feature names for transformation.
499+
500+
Parameters
501+
----------
502+
input_features : array-like of str or None, default=None
503+
Ignored.
504+
505+
Returns
506+
-------
507+
feature_names_out : ndarray of str objects
508+
Transformed feature names.
509+
"""
510+
check_is_fitted(self, "all_outputs_")
511+
return self.all_outputs_
512+
495513

496514
class _SplineEncoder(SingleColumnTransformer):
497515
"""Generate univariate B-spline bases for features.

skrub/tests/test_datetime_encoder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ def test_all_outputs_choice(datetime_cols, params, all_outputs):
299299
enc = DatetimeEncoder(**params)
300300
res = enc.fit_transform(datetime_cols.datetime)
301301
assert enc.all_outputs_ == [f"when_{f}" for f in all_outputs]
302+
assert enc.get_feature_names_out() == [f"when_{f}" for f in all_outputs]
302303
assert sbd.column_names(res) == [f"{f}" for f in enc.all_outputs_]
303304

304305

0 commit comments

Comments
 (0)