def _sparse_transform(self, X, valid_stats, valid_idx):
        mask = _get_mask(X.data, self.missing_values)
        indexes = np.repeat(np.arange(len(X.indptr) - 1, dtype=np.int),
                            np.diff(X.indptr))[mask]

        X.data[mask] = astype(valid_stats[indexes], X.dtype,
                              copy=False)

        mask_matrix = X.__class__((mask, X.indices.copy(),
                                  X.indptr.copy()), shape=X.shape,
                                  dtype=X.dtype)
        mask_matrix.eliminate_zeros()  # removes explicit False entries
        features_with_missing_values = mask_matrix.sum(axis=0).A.nonzero()[1]
        features_mask = safe_mask(mask_matrix, features_with_missing_values)
        imputed_mask = mask_matrix[:, features_mask]
        if self.axis == 0:
            self.imputed_features_ = valid_idx[features_with_missing_values]
        else:
            self.imputed_features_ = features_with_missing_values

        if self.add_indicator_features:
            X = sparse.hstack((X, imputed_mask))

        return X
transformer on sparse data.
dataset/ETHPy150Open scikit-learn/scikit-learn/sklearn/preprocessing/imputation.py/Imputer._sparse_transform