27
27
28
28
class TestDataFrameToCSV :
29
29
def read_csv (self , path , ** kwargs ):
30
- params = {"index_col" : 0 , "parse_dates" : True }
30
+ params = {"index_col" : 0 }
31
31
params .update (** kwargs )
32
32
33
33
return read_csv (path , ** params )
@@ -46,17 +46,17 @@ def test_to_csv_from_csv1(self, float_frame, datetime_frame):
46
46
# freq does not roundtrip
47
47
datetime_frame .index = datetime_frame .index ._with_freq (None )
48
48
datetime_frame .to_csv (path )
49
- recons = self .read_csv (path )
49
+ recons = self .read_csv (path , parse_dates = True )
50
50
tm .assert_frame_equal (datetime_frame , recons )
51
51
52
52
datetime_frame .to_csv (path , index_label = "index" )
53
- recons = self .read_csv (path , index_col = None )
53
+ recons = self .read_csv (path , index_col = None , parse_dates = True )
54
54
55
55
assert len (recons .columns ) == len (datetime_frame .columns ) + 1
56
56
57
57
# no index
58
58
datetime_frame .to_csv (path , index = False )
59
- recons = self .read_csv (path , index_col = None )
59
+ recons = self .read_csv (path , index_col = None , parse_dates = True )
60
60
tm .assert_almost_equal (datetime_frame .values , recons .values )
61
61
62
62
# corner case
@@ -514,7 +514,10 @@ def test_to_csv_multiindex(self, float_frame, datetime_frame):
514
514
tsframe .index = MultiIndex .from_arrays (new_index )
515
515
516
516
tsframe .to_csv (path , index_label = ["time" , "foo" ])
517
- recons = self .read_csv (path , index_col = [0 , 1 ])
517
+ with tm .assert_produces_warning (
518
+ UserWarning , match = "Could not infer format"
519
+ ):
520
+ recons = self .read_csv (path , index_col = [0 , 1 ], parse_dates = True )
518
521
519
522
# TODO to_csv drops column name
520
523
tm .assert_frame_equal (tsframe , recons , check_names = False )
@@ -1056,7 +1059,7 @@ def test_to_csv_date_format(self, datetime_frame):
1056
1059
1057
1060
# test NaTs
1058
1061
nat_index = to_datetime (
1059
- ["NaT" ] * 10 + ["2000-01-01" , "1/1/ 2000" , "1-1-2000 " ]
1062
+ ["NaT" ] * 10 + ["2000-01-01" , "2000-01-01 " , "2000-01-01 " ]
1060
1063
)
1061
1064
nat_frame = DataFrame ({"A" : nat_index }, index = nat_index )
1062
1065
nat_frame .to_csv (path , date_format = "%Y-%m-%d" )
0 commit comments