@@ -291,40 +291,17 @@ def test_check_array():
291291 assert_true (isinstance (result , np .ndarray ))
292292
293293 # deprecation warning if string-like array with dtype="numeric"
294- X_str = [['a' , 'b' ], ['c' , 'd' ]]
295- assert_warns_message (
296- FutureWarning ,
297- "arrays of strings will be interpreted as decimal numbers if "
298- "parameter 'dtype' is 'numeric'. It is recommended that you convert "
299- "the array to type np.float64 before passing it to check_array." ,
300- check_array , X_str , "numeric" )
301- assert_warns_message (
302- FutureWarning ,
303- "arrays of strings will be interpreted as decimal numbers if "
304- "parameter 'dtype' is 'numeric'. It is recommended that you convert "
305- "the array to type np.float64 before passing it to check_array." ,
306- check_array , np .array (X_str , dtype = 'U' ), "numeric" )
307- assert_warns_message (
308- FutureWarning ,
309- "arrays of strings will be interpreted as decimal numbers if "
310- "parameter 'dtype' is 'numeric'. It is recommended that you convert "
311- "the array to type np.float64 before passing it to check_array." ,
312- check_array , np .array (X_str , dtype = 'S' ), "numeric" )
294+ expected_warn_regex = r"converted to decimal numbers if dtype='numeric'"
295+ X_str = [['11' , '12' ], ['13' , 'xx' ]]
296+ for X in [X_str , np .array (X_str , dtype = 'U' ), np .array (X_str , dtype = 'S' )]:
297+ with pytest .warns (FutureWarning , match = expected_warn_regex ):
298+ check_array (X , dtype = "numeric" )
313299
314300 # deprecation warning if byte-like array with dtype="numeric"
315301 X_bytes = [[b'a' , b'b' ], [b'c' , b'd' ]]
316- assert_warns_message (
317- FutureWarning ,
318- "arrays of strings will be interpreted as decimal numbers if "
319- "parameter 'dtype' is 'numeric'. It is recommended that you convert "
320- "the array to type np.float64 before passing it to check_array." ,
321- check_array , X_bytes , "numeric" )
322- assert_warns_message (
323- FutureWarning ,
324- "arrays of strings will be interpreted as decimal numbers if "
325- "parameter 'dtype' is 'numeric'. It is recommended that you convert "
326- "the array to type np.float64 before passing it to check_array." ,
327- check_array , np .array (X_bytes , dtype = 'V1' ), "numeric" )
302+ for X in [X_bytes , np .array (X_bytes , dtype = 'V1' )]:
303+ with pytest .warns (FutureWarning , match = expected_warn_regex ):
304+ check_array (X , dtype = "numeric" )
328305
329306
330307def test_check_array_pandas_dtype_object_conversion ():
0 commit comments