@@ -363,6 +363,36 @@ def test_coerce_cast(dtypes, examples, data):
363363 assert expected_dtype .check (pandas_engine .Engine .dtype (coerced_dtype ))
364364
365365
366+ @pytest .mark .parametrize (
367+ "examples, type_, failure_indices" ,
368+ [
369+ (["a" , 0 , "b" ], int , [0 , 2 ]),
370+ (
371+ [
372+ "2021-09-01" ,
373+ datetime .datetime (2021 , 1 , 7 ),
374+ pd .NaT ,
375+ "not_a_date" ,
376+ ],
377+ datetime .datetime ,
378+ [3 ],
379+ ),
380+ ],
381+ )
382+ def test_try_coerce (examples , type_ , failure_indices ):
383+ """Test that try_coerce raises a ParseError."""
384+ data_type = pandas_engine .Engine .dtype (type_ )
385+ data = pd .Series (examples )
386+
387+ with pytest .raises (pa .errors .ParserError ):
388+ data_type .try_coerce (data )
389+
390+ try :
391+ data_type .try_coerce (data )
392+ except pa .errors .ParserError as exc :
393+ assert exc .failure_cases ["index" ].to_list () == failure_indices
394+
395+
366396def test_coerce_string ():
367397 """Test that strings can be coerced."""
368398 data = pd .Series ([1 , None ], dtype = "Int32" )
@@ -487,8 +517,7 @@ def test_is_float(float_dtype: Any, expected: bool):
487517
488518@pytest .mark .parametrize (
489519 "complex_dtype, expected" ,
490- [(dtype , True ) for dtype in complex_dtypes ]
491- + [("string" , False )], # type: ignore
520+ [(dtype , True ) for dtype in complex_dtypes ] + [("string" , False )], # type: ignore
492521)
493522def test_is_complex (complex_dtype : Any , expected : bool ):
494523 """Test is_complex."""
0 commit comments