@@ -586,7 +586,7 @@ def _validate_input(self, X):
586586
587587 return X
588588
589- def fit (self , X , y = None ):
589+ def _fit (self , X , y = None ):
590590 """Fit the transformer on X.
591591
592592 Parameters
@@ -597,8 +597,10 @@ def fit(self, X, y=None):
597597
598598 Returns
599599 -------
600- self : object
601- Returns self.
600+ imputer_mask : {ndarray or sparse matrix}, shape (n_samples, \
601+ n_features)
602+ The imputer mask of the original data.
603+
602604 """
603605 X = self ._validate_input (X )
604606 self ._n_features = X .shape [1 ]
@@ -612,7 +614,26 @@ def fit(self, X, y=None):
612614 raise ValueError ("'sparse' has to be a boolean or 'auto'. "
613615 "Got {!r} instead." .format (self .sparse ))
614616
615- self .features_ = self ._get_missing_features_info (X )[1 ]
617+ missing_features_info = self ._get_missing_features_info (X )
618+ self .features_ = missing_features_info [1 ]
619+
620+ return missing_features_info [0 ]
621+
622+ def fit (self , X , y = None ):
623+ """Fit the transformer on X.
624+
625+ Parameters
626+ ----------
627+ X : {array-like, sparse matrix}, shape (n_samples, n_features)
628+ Input data, where ``n_samples`` is the number of samples and
629+ ``n_features`` is the number of features.
630+
631+ Returns
632+ -------
633+ self : object
634+ Returns self.
635+ """
636+ self ._fit (X , y )
616637
617638 return self
618639
@@ -667,7 +688,12 @@ def fit_transform(self, X, y=None):
667688 will be boolean.
668689
669690 """
670- return self .fit (X , y ).transform (X )
691+ imputer_mask = self ._fit (X , y )
692+
693+ if self .features_ .size < self ._n_features :
694+ imputer_mask = imputer_mask [:, self .features_ ]
695+
696+ return imputer_mask
671697
672698 def _more_tags (self ):
673699 return {'allow_nan' : True ,
0 commit comments