@@ -119,27 +119,30 @@ def test_number_looking_strings_not_into_datetime(data):
119119
120120
121121@pytest .mark .parametrize (
122- "invalid_date" ,
122+ "invalid_date, warn " ,
123123 [
124- date (1000 , 1 , 1 ),
125- datetime (1000 , 1 , 1 ),
126- "1000-01-01" ,
127- "Jan 1, 1000" ,
128- np .datetime64 ("1000-01-01" ),
124+ ( date (1000 , 1 , 1 ), None ),
125+ ( datetime (1000 , 1 , 1 ), None ),
126+ ( "1000-01-01" , None ) ,
127+ ( "Jan 1, 1000" , UserWarning ) ,
128+ ( np .datetime64 ("1000-01-01" ), None ),
129129 ],
130130)
131131@pytest .mark .parametrize ("errors" , ["coerce" , "raise" ])
132- def test_coerce_outside_ns_bounds (invalid_date , errors ):
132+ def test_coerce_outside_ns_bounds (invalid_date , warn , errors ):
133133 arr = np .array ([invalid_date ], dtype = "object" )
134134 kwargs = {"values" : arr , "errors" : errors }
135135
136136 if errors == "raise" :
137137 msg = "Out of bounds .* present at position 0"
138138
139- with pytest .raises (ValueError , match = msg ):
139+ with pytest .raises (ValueError , match = msg ), tm .assert_produces_warning (
140+ warn , match = "without a format specified"
141+ ):
140142 tslib .array_to_datetime (** kwargs )
141143 else : # coerce.
142- result , _ = tslib .array_to_datetime (** kwargs )
144+ with tm .assert_produces_warning (warn , match = "without a format specified" ):
145+ result , _ = tslib .array_to_datetime (** kwargs )
143146 expected = np .array ([iNaT ], dtype = "M8[ns]" )
144147
145148 tm .assert_numpy_array_equal (result , expected )
@@ -163,17 +166,11 @@ def test_coerce_of_invalid_datetimes(errors):
163166 if errors == "ignore" :
164167 # Without coercing, the presence of any invalid
165168 # dates prevents any values from being converted.
166- with tm .assert_produces_warning (
167- UserWarning , match = "without a format specified"
168- ):
169- result , _ = tslib .array_to_datetime (** kwargs )
169+ result , _ = tslib .array_to_datetime (** kwargs )
170170 tm .assert_numpy_array_equal (result , arr )
171171 else : # coerce.
172172 # With coercing, the invalid dates becomes iNaT
173- with tm .assert_produces_warning (
174- UserWarning , match = "without a format specified"
175- ):
176- result , _ = tslib .array_to_datetime (arr , errors = "coerce" )
173+ result , _ = tslib .array_to_datetime (arr , errors = "coerce" )
177174 expected = ["2013-01-01T00:00:00.000000000" , iNaT , iNaT ]
178175
179176 tm .assert_numpy_array_equal (result , np .array (expected , dtype = "M8[ns]" ))
0 commit comments