@@ -1168,12 +1168,13 @@ def test_multiple_date_cols_chunked(all_parsers):
11681168 columns = ["nominal" , "ID" , "actualTime" , "A" , "B" , "C" , "D" , "E" ],
11691169 )
11701170 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" ,
11721174 StringIO (data ),
11731175 parse_dates = {"nominal" : [1 , 2 ]},
11741176 index_col = "nominal" ,
11751177 chunksize = 2 ,
1176- date_parser = lambda x : pd .to_datetime (x , format = "%Y%m%d %H:%M:%S" ),
11771178 ) as reader :
11781179 chunks = list (reader )
11791180
@@ -1195,17 +1196,19 @@ def test_multiple_date_col_named_index_compat(all_parsers):
11951196KORD,19990127, 23:00:00, 22:56:00, -0.5900, 1.7100, 4.6000, 0.0000, 280.0000
11961197"""
11971198
1198- with_indices = parser .read_csv (
1199+ with_indices = parser .read_csv_check_warnings (
1200+ UserWarning ,
1201+ "without a format specified" ,
11991202 StringIO (data ),
12001203 parse_dates = {"nominal" : [1 , 2 ]},
12011204 index_col = "nominal" ,
1202- date_parser = lambda x : pd .to_datetime (x , format = "%Y%m%d %H:%M:%S" ),
12031205 )
1204- with_names = parser .read_csv (
1206+ with_names = parser .read_csv_check_warnings (
1207+ UserWarning ,
1208+ "without a format specified" ,
12051209 StringIO (data ),
12061210 index_col = "nominal" ,
12071211 parse_dates = {"nominal" : ["date" , "nominalTime" ]},
1208- date_parser = lambda x : pd .to_datetime (x , format = "%Y%m%d %H:%M:%S" ),
12091212 )
12101213 tm .assert_frame_equal (with_indices , with_names )
12111214
@@ -1222,16 +1225,18 @@ def test_multiple_date_col_multiple_index_compat(all_parsers):
12221225KORD,19990127, 22:00:00, 21:56:00, -0.5900, 1.7100, 5.1000, 0.0000, 290.0000
12231226KORD,19990127, 23:00:00, 22:56:00, -0.5900, 1.7100, 4.6000, 0.0000, 280.0000
12241227"""
1225- result = parser .read_csv (
1228+ result = parser .read_csv_check_warnings (
1229+ UserWarning ,
1230+ "without a format specified" ,
12261231 StringIO (data ),
12271232 index_col = ["nominal" , "ID" ],
12281233 parse_dates = {"nominal" : [1 , 2 ]},
1229- date_parser = lambda x : pd .to_datetime (x , format = "%Y%m%d %H:%M:%S" ),
12301234 )
1231- expected = parser .read_csv (
1235+ expected = parser .read_csv_check_warnings (
1236+ UserWarning ,
1237+ "without a format specified" ,
12321238 StringIO (data ),
12331239 parse_dates = {"nominal" : [1 , 2 ]},
1234- date_parser = lambda x : pd .to_datetime (x , format = "%Y%m%d %H:%M:%S" ),
12351240 )
12361241
12371242 expected = expected .set_index (["nominal" , "ID" ])
@@ -1268,38 +1273,21 @@ def test_read_with_parse_dates_invalid_type(all_parsers, parse_dates):
12681273
12691274
12701275@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 ):
12891278 # if we have an invalid date make sure that we handle this with
12901279 # and w/o the cache properly
12911280 parser = all_parsers
12921281 s = StringIO ((f"{ value } ,\n " ) * 50000 )
12931282
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+ )
13031291
13041292
13051293@xfail_pyarrow
0 commit comments