@@ -119,27 +119,30 @@ def test_number_looking_strings_not_into_datetime(data):
119
119
120
120
121
121
@pytest .mark .parametrize (
122
- "invalid_date" ,
122
+ "invalid_date, warn " ,
123
123
[
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 ),
129
129
],
130
130
)
131
131
@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 ):
133
133
arr = np .array ([invalid_date ], dtype = "object" )
134
134
kwargs = {"values" : arr , "errors" : errors }
135
135
136
136
if errors == "raise" :
137
137
msg = "Out of bounds .* present at position 0"
138
138
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
+ ):
140
142
tslib .array_to_datetime (** kwargs )
141
143
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 )
143
146
expected = np .array ([iNaT ], dtype = "M8[ns]" )
144
147
145
148
tm .assert_numpy_array_equal (result , expected )
@@ -163,17 +166,11 @@ def test_coerce_of_invalid_datetimes(errors):
163
166
if errors == "ignore" :
164
167
# Without coercing, the presence of any invalid
165
168
# 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 )
170
170
tm .assert_numpy_array_equal (result , arr )
171
171
else : # coerce.
172
172
# 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" )
177
174
expected = ["2013-01-01T00:00:00.000000000" , iNaT , iNaT ]
178
175
179
176
tm .assert_numpy_array_equal (result , np .array (expected , dtype = "M8[ns]" ))
0 commit comments