#NEWLINE# def test_check_array_dtype_warning( ) : #NEWLINE# #INDENT# X_int_list = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ] #NEWLINE# X_float64 = np . asarray ( X_int_list , dtype = np . float64 ) #NEWLINE# X_float32 = np . asarray ( X_int_list , dtype = np . float32 ) #NEWLINE# X_int64 = np . asarray ( X_int_list , dtype = np . int64 ) #NEWLINE# X_csr_float64 = sp . csr_matrix ( X_float64 ) #NEWLINE# X_csr_float32 = sp . csr_matrix ( X_float32 ) #NEWLINE# X_csc_float32 = sp . csc_matrix ( X_float32 ) #NEWLINE# X_csc_int32 = sp . csc_matrix ( X_int64 , dtype = np . int32 ) #NEWLINE# y = [ 0 , 0 , 1 ] #NEWLINE# integer_data = [ X_int64 , X_csc_int32 ] #NEWLINE# float64_data = [ X_float64 , X_csr_float64 ] #NEWLINE# float32_data = [ X_float32 , X_csr_float32 , X_csc_float32 ] #NEWLINE# for X in integer_data : #NEWLINE# #INDENT# X_checked = assert_no_warnings ( check_array , X , dtype = np . float64 , accept_sparse = True ) #NEWLINE# assert_equal ( X_checked . dtype , np . float64 ) #NEWLINE# X_checked = assert_warns ( DataConversionWarning , check_array , X , dtype = np . float64 , accept_sparse = True , warn_on_dtype = True ) #NEWLINE# assert_equal ( X_float32 . dtype , np . float64 ) #NEWLINE# X_checked = assert_warns_message ( DataConversionWarning , 'SomeEstimator' , check_array , X , dtype = [ np . float64 , np . float32 ] , accept_sparse = True , warn_on_dtype = True , estimator = 'SomeEstimator' ) #NEWLINE# assert_equal ( X_checked . dtype , np . float64 ) #NEWLINE# ( X_checked , y_checked ) = assert_warns_message ( DataConversionWarning , 'KNeighborsClassifier' , check_X_y , X , y , dtype = np . float64 , accept_sparse = True , warn_on_dtype = True , estimator = KNeighborsClassifier ( ) ) #NEWLINE# assert_equal ( X_checked . dtype , np . float64 ) #NEWLINE# #UNINDENT# for X in float64_data : #NEWLINE# #INDENT# X_checked = assert_no_warnings ( check_array , X , dtype = np . float64 , accept_sparse = True , warn_on_dtype = True ) #NEWLINE# assert_equal ( X_checked . dtype , np . float64 ) #NEWLINE# X_checked = assert_no_warnings ( check_array , X , dtype = np . float64 , accept_sparse = True , warn_on_dtype = False ) #NEWLINE# assert_equal ( X_checked . dtype , np . float64 ) #NEWLINE# #UNINDENT# for X in float32_data : #NEWLINE# #INDENT# X_checked = assert_no_warnings ( check_array , X , dtype = [ np . float64 , np . float32 ] , accept_sparse = True ) #NEWLINE# assert_equal ( X_checked . dtype , np . float32 ) #NEWLINE# assert_true ( ( X_checked is X ) ) #NEWLINE# X_checked = assert_no_warnings ( check_array , X , dtype = [ np . float64 , np . float32 ] , accept_sparse = [ 'csr' , 'dok' ] , copy = True ) #NEWLINE# assert_equal ( X_checked . dtype , np . float32 ) #NEWLINE# assert_false ( ( X_checked is X ) ) #NEWLINE# #UNINDENT# X_checked = assert_no_warnings ( check_array , X_csc_float32 , dtype = [ np . float64 , np . float32 ] , accept_sparse = [ 'csr' , 'dok' ] , copy = False ) #NEWLINE# assert_equal ( X_checked . dtype , np . float32 ) #NEWLINE# assert_false ( ( X_checked is X_csc_float32 ) ) #NEWLINE# assert_equal ( X_checked . format , 'csr' )