#NEWLINE# def transform( self , X ) : #NEWLINE# #INDENT# 'Impute all missing values in X.\n\n        Parameters\n        ----------\n        X : {array-like, sparse matrix}, shape = (n_samples, n_features)\n            The input data to complete.\n\n        Return\n        ------\n        X_new : {array-like, sparse matrix},\n                Transformed array.\n                shape (n_samples, n_features_new) when\n                ``add_indicator_features`` is False,\n                shape (n_samples, n_features_new + len(imputed_features_)\n                when ``add_indicator_features`` is True.\n        ' #NEWLINE# if ( self . axis == 0 ) : #NEWLINE# #INDENT# check_is_fitted ( valid_idx , 'statistics_' ) #NEWLINE# #UNINDENT# if ( self . axis == 1 ) : #NEWLINE# #INDENT# X = check_array ( X , accept_sparse = 'csr' , dtype = FLOAT_DTYPES , force_all_finite = False , copy = self . copy ) #NEWLINE# if sparse . issparse ( X ) : #NEWLINE# #INDENT# statistics = self . _sparse_fit ( X , self . strategy , self . missing_values , self . axis ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# statistics = self . _dense_fit ( X , self . strategy , self . missing_values , self . axis ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# X = check_array ( X , accept_sparse = 'csc' , dtype = FLOAT_DTYPES , force_all_finite = False , copy = self . copy ) #NEWLINE# statistics = self . statistics_ #NEWLINE# #UNINDENT# invalid_mask = np . isnan ( statistics ) #NEWLINE# valid_mask = np . logical_not ( invalid_mask ) #NEWLINE# valid_statistics = statistics [ valid_mask ] #NEWLINE# valid_idx = np . where ( valid_mask ) [ 0 ] #NEWLINE# missing = np . arange ( X . shape [ ( not self . axis ) ] ) [ invalid_mask ] #NEWLINE# if ( ( self . axis == 0 ) and invalid_mask . any ( ) ) : #NEWLINE# #INDENT# if self . verbose : #NEWLINE# #INDENT# warnings . warn ( ( 'Deleting features without observed values: %s' % missing ) ) #NEWLINE# #UNINDENT# X = X [ : , valid_idx ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( self . axis == 1 ) and invalid_mask . any ( ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Some rows only contain missing values: %s' % missing ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( sparse . issparse ( X ) and ( self . missing_values != 0 ) ) : #NEWLINE# #INDENT# X = self . _sparse_transform ( X , valid_statistics , valid_idx ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if sparse . issparse ( X ) : #NEWLINE# #INDENT# X = X . toarray ( ) #NEWLINE# #UNINDENT# X = self . _dense_transform ( X , valid_statistics , valid_idx ) #NEWLINE# #UNINDENT# return X