@@ -6618,31 +6618,25 @@ def test_to_csv_cols_reordering(self):
6618
6618
# GH3454
6619
6619
import pandas as pd
6620
6620
6621
- def _check_df(df,cols=None):
6622
- with ensure_clean() as path:
6623
- df.to_csv(path,columns = cols,engine='python')
6624
- rs_p = pd.read_csv(path,index_col=0)
6625
- df.to_csv(path,columns = cols,chunksize=chunksize)
6626
- rs_c = pd.read_csv(path,index_col=0)
6627
-
6628
- if cols:
6629
- df = df[cols]
6630
- assert (rs_c.columns==rs_p.columns).all()
6631
- assert_frame_equal(df,rs_c,check_names=False)
6632
-
6633
6621
chunksize=5
6634
6622
N = int(chunksize*2.5)
6635
6623
6636
6624
df= mkdf(N, 3)
6637
6625
cs = df.columns
6638
6626
cols = [cs[2],cs[0]]
6639
- _check_df(df,cols)
6627
+
6628
+ with ensure_clean() as path:
6629
+ df.to_csv(path,columns = cols,chunksize=chunksize)
6630
+ rs_c = pd.read_csv(path,index_col=0)
6631
+
6632
+ assert_frame_equal(df[cols],rs_c,check_names=False)
6640
6633
6641
6634
def test_to_csv_legacy_raises_on_dupe_cols(self):
6642
6635
df= mkdf(10, 3)
6643
6636
df.columns = ['a','a','b']
6644
6637
with ensure_clean() as path:
6645
- self.assertRaises(NotImplementedError,df.to_csv,path,engine='python')
6638
+ with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
6639
+ self.assertRaises(NotImplementedError,df.to_csv,path,engine='python')
6646
6640
6647
6641
def test_to_csv_new_dupe_cols(self):
6648
6642
import pandas as pd
@@ -15198,10 +15192,14 @@ def test_to_csv_date_format(self):
15198
15192
pname = '__tmp_to_csv_date_format__'
15199
15193
with ensure_clean(pname) as path:
15200
15194
for engine in [None, 'python']:
15195
+ w = FutureWarning if engine == 'python' else None
15196
+
15201
15197
dt_index = self.tsframe.index
15202
15198
datetime_frame = DataFrame({'A': dt_index, 'B': dt_index.shift(1)}, index=dt_index)
15203
15199
15204
- datetime_frame.to_csv(path, date_format='%Y%m%d', engine=engine)
15200
+ with tm.assert_produces_warning(w, check_stacklevel=False):
15201
+ datetime_frame.to_csv(path, date_format='%Y%m%d', engine=engine)
15202
+
15205
15203
# Check that the data was put in the specified format
15206
15204
test = read_csv(path, index_col=0)
15207
15205
@@ -15210,7 +15208,9 @@ def test_to_csv_date_format(self):
15210
15208
15211
15209
assert_frame_equal(test, datetime_frame_int)
15212
15210
15213
- datetime_frame.to_csv(path, date_format='%Y-%m-%d', engine=engine)
15211
+ with tm.assert_produces_warning(w, check_stacklevel=False):
15212
+ datetime_frame.to_csv(path, date_format='%Y-%m-%d', engine=engine)
15213
+
15214
15214
# Check that the data was put in the specified format
15215
15215
test = read_csv(path, index_col=0)
15216
15216
datetime_frame_str = datetime_frame.applymap(lambda x: x.strftime('%Y-%m-%d'))
@@ -15221,7 +15221,8 @@ def test_to_csv_date_format(self):
15221
15221
# Check that columns get converted
15222
15222
datetime_frame_columns = datetime_frame.T
15223
15223
15224
- datetime_frame_columns.to_csv(path, date_format='%Y%m%d', engine=engine)
15224
+ with tm.assert_produces_warning(w, check_stacklevel=False):
15225
+ datetime_frame_columns.to_csv(path, date_format='%Y%m%d', engine=engine)
15225
15226
15226
15227
test = read_csv(path, index_col=0)
15227
15228
@@ -15235,7 +15236,8 @@ def test_to_csv_date_format(self):
15235
15236
nat_index = to_datetime(['NaT'] * 10 + ['2000-01-01', '1/1/2000', '1-1-2000'])
15236
15237
nat_frame = DataFrame({'A': nat_index}, index=nat_index)
15237
15238
15238
- nat_frame.to_csv(path, date_format='%Y-%m-%d', engine=engine)
15239
+ with tm.assert_produces_warning(w, check_stacklevel=False):
15240
+ nat_frame.to_csv(path, date_format='%Y-%m-%d', engine=engine)
15239
15241
15240
15242
test = read_csv(path, parse_dates=[0, 1], index_col=0)
15241
15243
0 commit comments