@@ -43,25 +43,36 @@ def test_to_csv_from_csv1(self):
43
43
44
44
# test roundtrip
45
45
self .tsframe .to_csv (path )
46
- recons = DataFrame .from_csv (path )
47
46
48
- assert_frame_equal (self .tsframe , recons )
47
+ with tm .assert_produces_warning (FutureWarning ,
48
+ check_stacklevel = False ):
49
+ recons = DataFrame .from_csv (path )
50
+ assert_frame_equal (self .tsframe , recons )
49
51
50
52
self .tsframe .to_csv (path , index_label = 'index' )
51
- recons = DataFrame .from_csv (path , index_col = None )
52
- assert (len (recons .columns ) == len (self .tsframe .columns ) + 1 )
53
+
54
+ with tm .assert_produces_warning (FutureWarning ,
55
+ check_stacklevel = False ):
56
+ recons = DataFrame .from_csv (path , index_col = None )
57
+ assert (len (recons .columns ) == len (self .tsframe .columns ) + 1 )
53
58
54
59
# no index
55
60
self .tsframe .to_csv (path , index = False )
56
- recons = DataFrame .from_csv (path , index_col = None )
57
- assert_almost_equal (self .tsframe .values , recons .values )
61
+
62
+ with tm .assert_produces_warning (FutureWarning ,
63
+ check_stacklevel = False ):
64
+ recons = DataFrame .from_csv (path , index_col = None )
65
+ assert_almost_equal (self .tsframe .values , recons .values )
58
66
59
67
# corner case
60
68
dm = DataFrame ({'s1' : Series (lrange (3 ), lrange (3 )),
61
69
's2' : Series (lrange (2 ), lrange (2 ))})
62
70
dm .to_csv (path )
63
- recons = DataFrame .from_csv (path )
64
- assert_frame_equal (dm , recons )
71
+
72
+ with tm .assert_produces_warning (FutureWarning ,
73
+ check_stacklevel = False ):
74
+ recons = DataFrame .from_csv (path )
75
+ assert_frame_equal (dm , recons )
65
76
66
77
def test_to_csv_from_csv2 (self ):
67
78
@@ -71,28 +82,36 @@ def test_to_csv_from_csv2(self):
71
82
df = DataFrame (np .random .randn (3 , 3 ), index = ['a' , 'a' , 'b' ],
72
83
columns = ['x' , 'y' , 'z' ])
73
84
df .to_csv (path )
74
- result = DataFrame .from_csv (path )
75
- assert_frame_equal (result , df )
85
+
86
+ with tm .assert_produces_warning (FutureWarning ,
87
+ check_stacklevel = False ):
88
+ result = DataFrame .from_csv (path )
89
+ assert_frame_equal (result , df )
76
90
77
91
midx = MultiIndex .from_tuples (
78
92
[('A' , 1 , 2 ), ('A' , 1 , 2 ), ('B' , 1 , 2 )])
79
93
df = DataFrame (np .random .randn (3 , 3 ), index = midx ,
80
94
columns = ['x' , 'y' , 'z' ])
81
95
df .to_csv (path )
82
- result = DataFrame .from_csv (path , index_col = [0 , 1 , 2 ],
83
- parse_dates = False )
96
+
97
+ with tm .assert_produces_warning (FutureWarning ,
98
+ check_stacklevel = False ):
99
+ result = DataFrame .from_csv (path , index_col = [0 , 1 , 2 ],
100
+ parse_dates = False )
84
101
# TODO from_csv names index ['Unnamed: 1', 'Unnamed: 2'] should it
85
102
# ?
86
103
assert_frame_equal (result , df , check_names = False )
87
104
88
105
# column aliases
89
106
col_aliases = Index (['AA' , 'X' , 'Y' , 'Z' ])
90
107
self .frame2 .to_csv (path , header = col_aliases )
91
- rs = DataFrame .from_csv (path )
92
- xp = self .frame2 .copy ()
93
- xp .columns = col_aliases
94
108
95
- assert_frame_equal (xp , rs )
109
+ with tm .assert_produces_warning (FutureWarning ,
110
+ check_stacklevel = False ):
111
+ rs = DataFrame .from_csv (path )
112
+ xp = self .frame2 .copy ()
113
+ xp .columns = col_aliases
114
+ assert_frame_equal (xp , rs )
96
115
97
116
pytest .raises (ValueError , self .frame2 .to_csv , path ,
98
117
header = ['AA' , 'X' ])
@@ -231,10 +250,13 @@ def make_dtnat_arr(n, nnat=None):
231
250
with ensure_clean ('1.csv' ) as pth :
232
251
df = DataFrame (dict (a = s1 , b = s2 ))
233
252
df .to_csv (pth , chunksize = chunksize )
234
- recons = DataFrame .from_csv (pth )._convert (datetime = True ,
235
- coerce = True )
236
- assert_frame_equal (df , recons , check_names = False ,
237
- check_less_precise = True )
253
+
254
+ with tm .assert_produces_warning (FutureWarning ,
255
+ check_stacklevel = False ):
256
+ recons = DataFrame .from_csv (pth )._convert (datetime = True ,
257
+ coerce = True )
258
+ assert_frame_equal (df , recons , check_names = False ,
259
+ check_less_precise = True )
238
260
239
261
@pytest .mark .slow
240
262
def test_to_csv_moar (self ):
@@ -250,13 +272,19 @@ def _do_test(df, r_dtype=None, c_dtype=None,
250
272
with ensure_clean ('__tmp_to_csv_moar__' ) as path :
251
273
df .to_csv (path , encoding = 'utf8' ,
252
274
chunksize = chunksize , tupleize_cols = False )
253
- recons = DataFrame .from_csv (
254
- path , tupleize_cols = False , ** kwargs )
275
+
276
+ with tm .assert_produces_warning (FutureWarning ,
277
+ check_stacklevel = False ):
278
+ recons = DataFrame .from_csv (
279
+ path , tupleize_cols = False , ** kwargs )
255
280
else :
256
281
kwargs ['header' ] = 0
257
282
with ensure_clean ('__tmp_to_csv_moar__' ) as path :
258
283
df .to_csv (path , encoding = 'utf8' , chunksize = chunksize )
259
- recons = DataFrame .from_csv (path , ** kwargs )
284
+
285
+ with tm .assert_produces_warning (FutureWarning ,
286
+ check_stacklevel = False ):
287
+ recons = DataFrame .from_csv (path , ** kwargs )
260
288
261
289
def _to_uni (x ):
262
290
if not isinstance (x , compat .text_type ):
@@ -398,12 +426,15 @@ def test_to_csv_from_csv_w_some_infs(self):
398
426
399
427
with ensure_clean () as path :
400
428
self .frame .to_csv (path )
401
- recons = DataFrame .from_csv (path )
402
429
403
- # TODO to_csv drops column name
404
- assert_frame_equal (self .frame , recons , check_names = False )
405
- assert_frame_equal (np .isinf (self .frame ),
406
- np .isinf (recons ), check_names = False )
430
+ with tm .assert_produces_warning (FutureWarning ,
431
+ check_stacklevel = False ):
432
+ recons = DataFrame .from_csv (path )
433
+
434
+ # TODO to_csv drops column name
435
+ assert_frame_equal (self .frame , recons , check_names = False )
436
+ assert_frame_equal (np .isinf (self .frame ),
437
+ np .isinf (recons ), check_names = False )
407
438
408
439
def test_to_csv_from_csv_w_all_infs (self ):
409
440
@@ -413,12 +444,15 @@ def test_to_csv_from_csv_w_all_infs(self):
413
444
414
445
with ensure_clean () as path :
415
446
self .frame .to_csv (path )
416
- recons = DataFrame .from_csv (path )
417
447
418
- # TODO to_csv drops column name
419
- assert_frame_equal (self .frame , recons , check_names = False )
420
- assert_frame_equal (np .isinf (self .frame ),
421
- np .isinf (recons ), check_names = False )
448
+ with tm .assert_produces_warning (FutureWarning ,
449
+ check_stacklevel = False ):
450
+ recons = DataFrame .from_csv (path )
451
+
452
+ # TODO to_csv drops column name
453
+ assert_frame_equal (self .frame , recons , check_names = False )
454
+ assert_frame_equal (np .isinf (self .frame ),
455
+ np .isinf (recons ), check_names = False )
422
456
423
457
def test_to_csv_no_index (self ):
424
458
# GH 3624, after appending columns, to_csv fails
@@ -448,13 +482,19 @@ def test_to_csv_headers(self):
448
482
to_df = DataFrame ([[1 , 2 ], [3 , 4 ]], columns = ['X' , 'Y' ])
449
483
with ensure_clean ('__tmp_to_csv_headers__' ) as path :
450
484
from_df .to_csv (path , header = ['X' , 'Y' ])
451
- recons = DataFrame .from_csv (path )
452
- assert_frame_equal (to_df , recons )
485
+
486
+ with tm .assert_produces_warning (FutureWarning ,
487
+ check_stacklevel = False ):
488
+ recons = DataFrame .from_csv (path )
489
+ assert_frame_equal (to_df , recons )
453
490
454
491
from_df .to_csv (path , index = False , header = ['X' , 'Y' ])
455
- recons = DataFrame .from_csv (path )
456
- recons .reset_index (inplace = True )
457
- assert_frame_equal (to_df , recons )
492
+
493
+ with tm .assert_produces_warning (FutureWarning ,
494
+ check_stacklevel = False ):
495
+ recons = DataFrame .from_csv (path )
496
+ recons .reset_index (inplace = True )
497
+ assert_frame_equal (to_df , recons )
458
498
459
499
def test_to_csv_multiindex (self ):
460
500
@@ -471,11 +511,15 @@ def test_to_csv_multiindex(self):
471
511
472
512
# round trip
473
513
frame .to_csv (path )
474
- df = DataFrame .from_csv (path , index_col = [0 , 1 ], parse_dates = False )
475
514
476
- # TODO to_csv drops column name
477
- assert_frame_equal (frame , df , check_names = False )
478
- assert frame .index .names == df .index .names
515
+ with tm .assert_produces_warning (FutureWarning ,
516
+ check_stacklevel = False ):
517
+ df = DataFrame .from_csv (path , index_col = [0 , 1 ],
518
+ parse_dates = False )
519
+
520
+ # TODO to_csv drops column name
521
+ assert_frame_equal (frame , df , check_names = False )
522
+ assert frame .index .names == df .index .names
479
523
480
524
# needed if setUP becomes a classmethod
481
525
self .frame .index = old_index
@@ -487,19 +531,28 @@ def test_to_csv_multiindex(self):
487
531
tsframe .index = MultiIndex .from_arrays (new_index )
488
532
489
533
tsframe .to_csv (path , index_label = ['time' , 'foo' ])
490
- recons = DataFrame .from_csv (path , index_col = [0 , 1 ])
491
- # TODO to_csv drops column name
492
- assert_frame_equal (tsframe , recons , check_names = False )
534
+
535
+ with tm .assert_produces_warning (FutureWarning ,
536
+ check_stacklevel = False ):
537
+ recons = DataFrame .from_csv (path , index_col = [0 , 1 ])
538
+ # TODO to_csv drops column name
539
+ assert_frame_equal (tsframe , recons , check_names = False )
493
540
494
541
# do not load index
495
542
tsframe .to_csv (path )
496
- recons = DataFrame .from_csv (path , index_col = None )
497
- assert len (recons .columns ) == len (tsframe .columns ) + 2
543
+
544
+ with tm .assert_produces_warning (FutureWarning ,
545
+ check_stacklevel = False ):
546
+ recons = DataFrame .from_csv (path , index_col = None )
547
+ assert len (recons .columns ) == len (tsframe .columns ) + 2
498
548
499
549
# no index
500
550
tsframe .to_csv (path , index = False )
501
- recons = DataFrame .from_csv (path , index_col = None )
502
- assert_almost_equal (recons .values , self .tsframe .values )
551
+
552
+ with tm .assert_produces_warning (FutureWarning ,
553
+ check_stacklevel = False ):
554
+ recons = DataFrame .from_csv (path , index_col = None )
555
+ assert_almost_equal (recons .values , self .tsframe .values )
503
556
504
557
# needed if setUP becomes classmethod
505
558
self .tsframe .index = old_index
@@ -599,12 +652,15 @@ def _make_frame(names=None):
599
652
with ensure_clean ('__tmp_to_csv_multiindex__' ) as path :
600
653
# empty
601
654
tsframe [:0 ].to_csv (path )
602
- recons = DataFrame .from_csv (path )
603
- exp = tsframe [:0 ]
604
- exp .index = []
605
655
606
- tm .assert_index_equal (recons .columns , exp .columns )
607
- assert len (recons ) == 0
656
+ with tm .assert_produces_warning (FutureWarning ,
657
+ check_stacklevel = False ):
658
+ recons = DataFrame .from_csv (path )
659
+ exp = tsframe [:0 ]
660
+ exp .index = []
661
+
662
+ tm .assert_index_equal (recons .columns , exp .columns )
663
+ assert len (recons ) == 0
608
664
609
665
def test_to_csv_float32_nanrep (self ):
610
666
df = DataFrame (np .random .randn (1 , 4 ).astype (np .float32 ))
@@ -624,8 +680,11 @@ def test_to_csv_withcommas(self):
624
680
625
681
with ensure_clean ('__tmp_to_csv_withcommas__.csv' ) as path :
626
682
df .to_csv (path )
627
- df2 = DataFrame .from_csv (path )
628
- assert_frame_equal (df2 , df )
683
+
684
+ with tm .assert_produces_warning (FutureWarning ,
685
+ check_stacklevel = False ):
686
+ df2 = DataFrame .from_csv (path )
687
+ assert_frame_equal (df2 , df )
629
688
630
689
def test_to_csv_mixed (self ):
631
690
@@ -739,8 +798,11 @@ def test_to_csv_wide_frame_formatting(self):
739
798
740
799
def test_to_csv_bug (self ):
741
800
f1 = StringIO ('a,1.0\n b,2.0' )
742
- df = DataFrame .from_csv (f1 , header = None )
743
- newdf = DataFrame ({'t' : df [df .columns [0 ]]})
801
+
802
+ with tm .assert_produces_warning (FutureWarning ,
803
+ check_stacklevel = False ):
804
+ df = DataFrame .from_csv (f1 , header = None )
805
+ newdf = DataFrame ({'t' : df [df .columns [0 ]]})
744
806
745
807
with ensure_clean () as path :
746
808
newdf .to_csv (path )
0 commit comments