@@ -6618,31 +6618,25 @@ def test_to_csv_cols_reordering(self):
66186618 # GH3454
66196619 import pandas as pd
66206620
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-
66336621 chunksize=5
66346622 N = int(chunksize*2.5)
66356623
66366624 df= mkdf(N, 3)
66376625 cs = df.columns
66386626 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)
66406633
66416634 def test_to_csv_legacy_raises_on_dupe_cols(self):
66426635 df= mkdf(10, 3)
66436636 df.columns = ['a','a','b']
66446637 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')
66466640
66476641 def test_to_csv_new_dupe_cols(self):
66486642 import pandas as pd
@@ -15198,10 +15192,14 @@ def test_to_csv_date_format(self):
1519815192 pname = '__tmp_to_csv_date_format__'
1519915193 with ensure_clean(pname) as path:
1520015194 for engine in [None, 'python']:
15195+ w = FutureWarning if engine == 'python' else None
15196+
1520115197 dt_index = self.tsframe.index
1520215198 datetime_frame = DataFrame({'A': dt_index, 'B': dt_index.shift(1)}, index=dt_index)
1520315199
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+
1520515203 # Check that the data was put in the specified format
1520615204 test = read_csv(path, index_col=0)
1520715205
@@ -15210,7 +15208,9 @@ def test_to_csv_date_format(self):
1521015208
1521115209 assert_frame_equal(test, datetime_frame_int)
1521215210
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+
1521415214 # Check that the data was put in the specified format
1521515215 test = read_csv(path, index_col=0)
1521615216 datetime_frame_str = datetime_frame.applymap(lambda x: x.strftime('%Y-%m-%d'))
@@ -15221,7 +15221,8 @@ def test_to_csv_date_format(self):
1522115221 # Check that columns get converted
1522215222 datetime_frame_columns = datetime_frame.T
1522315223
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)
1522515226
1522615227 test = read_csv(path, index_col=0)
1522715228
@@ -15235,7 +15236,8 @@ def test_to_csv_date_format(self):
1523515236 nat_index = to_datetime(['NaT'] * 10 + ['2000-01-01', '1/1/2000', '1-1-2000'])
1523615237 nat_frame = DataFrame({'A': nat_index}, index=nat_index)
1523715238
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)
1523915241
1524015242 test = read_csv(path, parse_dates=[0, 1], index_col=0)
1524115243
0 commit comments