Skip to content

Commit c0995dd

Browse files
FIX - Make SelectCols and DropCols implement sklearn convention (skrub-data#1813)
1 parent 9005c1a commit c0995dd

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Changes
1717

1818
Bugfixes
1919
--------
20+
- :class:`DropCols` and :class:`SelectCols:` attributes were renamed to end
21+
with an underscore, in order to follow a scikit-learn convention which is
22+
used to determine if an estimator is fitted. :pr:`1813` by :user:`Auguste
23+
Baum <auguste-probabl>`.
2024

2125
Release 0.7.0
2226
=============

skrub/_select_cols.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def fit(self, X, y=None):
6363
SelectCols
6464
The transformer itself.
6565
"""
66-
self._columns = s.make_selector(self.cols).expand(X)
66+
self.columns_ = s.make_selector(self.cols).expand(X)
6767
return self
6868

6969
def transform(self, X):
@@ -80,7 +80,7 @@ def transform(self, X):
8080
The input DataFrame ``X`` after selecting only the columns listed
8181
in ``self.cols`` (in the provided order).
8282
"""
83-
return s.select(X, self._columns)
83+
return s.select(X, self.columns_)
8484

8585
def get_feature_names_out(self, input_features=None):
8686
"""Get output feature names for transformation.
@@ -95,8 +95,8 @@ def get_feature_names_out(self, input_features=None):
9595
feature_names_out : ndarray of str objects
9696
Transformed feature names.
9797
"""
98-
check_is_fitted(self, "_columns")
99-
return self._columns
98+
check_is_fitted(self, "columns_")
99+
return self.columns_
100100

101101

102102
class DropCols(TransformerMixin, BaseEstimator):
@@ -159,8 +159,8 @@ def fit(self, X, y=None):
159159
The transformer itself.
160160
"""
161161
selector = s.make_selector(self.cols)
162-
self._kept_cols = (~selector).expand(X)
163-
self._dropped_cols = selector.expand(X)
162+
self.kept_cols_ = (~selector).expand(X)
163+
self.dropped_cols_ = selector.expand(X)
164164
return self
165165

166166
def transform(self, X):
@@ -177,7 +177,7 @@ def transform(self, X):
177177
The input DataFrame ``X`` after dropping the columns listed in
178178
``self.cols``.
179179
"""
180-
return s.select(X, s.make_selector(self._kept_cols))
180+
return s.select(X, s.make_selector(self.kept_cols_))
181181

182182
def get_feature_names_out(self, input_features=None):
183183
"""Get output feature names for transformation.
@@ -192,8 +192,8 @@ def get_feature_names_out(self, input_features=None):
192192
feature_names_out : ndarray of str objects
193193
Transformed feature names.
194194
"""
195-
check_is_fitted(self, "_kept_cols")
196-
return self._kept_cols
195+
check_is_fitted(self, "kept_cols_")
196+
return self.kept_cols_
197197

198198

199199
class Drop(SingleColumnTransformer):

0 commit comments

Comments
 (0)