@@ -1168,12 +1168,13 @@ def test_multiple_date_cols_chunked(all_parsers):
1168
1168
columns = ["nominal" , "ID" , "actualTime" , "A" , "B" , "C" , "D" , "E" ],
1169
1169
)
1170
1170
expected = expected .set_index ("nominal" )
1171
- with parser .read_csv (
1171
+ with parser .read_csv_check_warnings (
1172
+ UserWarning ,
1173
+ "Parsing datetime strings without a format specified" ,
1172
1174
StringIO (data ),
1173
1175
parse_dates = {"nominal" : [1 , 2 ]},
1174
1176
index_col = "nominal" ,
1175
1177
chunksize = 2 ,
1176
- date_parser = lambda x : pd .to_datetime (x , format = "%Y%m%d %H:%M:%S" ),
1177
1178
) as reader :
1178
1179
chunks = list (reader )
1179
1180
@@ -1195,17 +1196,19 @@ def test_multiple_date_col_named_index_compat(all_parsers):
1195
1196
KORD,19990127, 23:00:00, 22:56:00, -0.5900, 1.7100, 4.6000, 0.0000, 280.0000
1196
1197
"""
1197
1198
1198
- with_indices = parser .read_csv (
1199
+ with_indices = parser .read_csv_check_warnings (
1200
+ UserWarning ,
1201
+ "without a format specified" ,
1199
1202
StringIO (data ),
1200
1203
parse_dates = {"nominal" : [1 , 2 ]},
1201
1204
index_col = "nominal" ,
1202
- date_parser = lambda x : pd .to_datetime (x , format = "%Y%m%d %H:%M:%S" ),
1203
1205
)
1204
- with_names = parser .read_csv (
1206
+ with_names = parser .read_csv_check_warnings (
1207
+ UserWarning ,
1208
+ "without a format specified" ,
1205
1209
StringIO (data ),
1206
1210
index_col = "nominal" ,
1207
1211
parse_dates = {"nominal" : ["date" , "nominalTime" ]},
1208
- date_parser = lambda x : pd .to_datetime (x , format = "%Y%m%d %H:%M:%S" ),
1209
1212
)
1210
1213
tm .assert_frame_equal (with_indices , with_names )
1211
1214
@@ -1222,16 +1225,18 @@ def test_multiple_date_col_multiple_index_compat(all_parsers):
1222
1225
KORD,19990127, 22:00:00, 21:56:00, -0.5900, 1.7100, 5.1000, 0.0000, 290.0000
1223
1226
KORD,19990127, 23:00:00, 22:56:00, -0.5900, 1.7100, 4.6000, 0.0000, 280.0000
1224
1227
"""
1225
- result = parser .read_csv (
1228
+ result = parser .read_csv_check_warnings (
1229
+ UserWarning ,
1230
+ "without a format specified" ,
1226
1231
StringIO (data ),
1227
1232
index_col = ["nominal" , "ID" ],
1228
1233
parse_dates = {"nominal" : [1 , 2 ]},
1229
- date_parser = lambda x : pd .to_datetime (x , format = "%Y%m%d %H:%M:%S" ),
1230
1234
)
1231
- expected = parser .read_csv (
1235
+ expected = parser .read_csv_check_warnings (
1236
+ UserWarning ,
1237
+ "without a format specified" ,
1232
1238
StringIO (data ),
1233
1239
parse_dates = {"nominal" : [1 , 2 ]},
1234
- date_parser = lambda x : pd .to_datetime (x , format = "%Y%m%d %H:%M:%S" ),
1235
1240
)
1236
1241
1237
1242
expected = expected .set_index (["nominal" , "ID" ])
@@ -1268,38 +1273,21 @@ def test_read_with_parse_dates_invalid_type(all_parsers, parse_dates):
1268
1273
1269
1274
1270
1275
@pytest .mark .parametrize ("cache_dates" , [True , False ])
1271
- @pytest .mark .parametrize (
1272
- "value, warning" ,
1273
- [
1274
- (
1275
- "nan" ,
1276
- (None , "" ),
1277
- ),
1278
- (
1279
- "0" ,
1280
- (UserWarning , "Parsing datetime strings without a format specified" ),
1281
- ),
1282
- (
1283
- "" ,
1284
- (None , "" ),
1285
- ),
1286
- ],
1287
- )
1288
- def test_bad_date_parse (all_parsers , cache_dates , value , warning ):
1276
+ @pytest .mark .parametrize ("value" , ["nan" , "0" , "" ])
1277
+ def test_bad_date_parse (all_parsers , cache_dates , value ):
1289
1278
# if we have an invalid date make sure that we handle this with
1290
1279
# and w/o the cache properly
1291
1280
parser = all_parsers
1292
1281
s = StringIO ((f"{ value } ,\n " ) * 50000 )
1293
1282
1294
- with tm .assert_produces_warning (None , raise_on_extra_warnings = False ):
1295
- parser .read_csv (
1296
- s ,
1297
- header = None ,
1298
- names = ["foo" , "bar" ],
1299
- parse_dates = ["foo" ],
1300
- infer_datetime_format = False ,
1301
- cache_dates = cache_dates ,
1302
- )
1283
+ parser .read_csv (
1284
+ s ,
1285
+ header = None ,
1286
+ names = ["foo" , "bar" ],
1287
+ parse_dates = ["foo" ],
1288
+ infer_datetime_format = False ,
1289
+ cache_dates = cache_dates ,
1290
+ )
1303
1291
1304
1292
1305
1293
@xfail_pyarrow
0 commit comments