Skip to content

Commit

Permalink
remove warnings from the tests for deprecation of engine in to_csv
Browse files Browse the repository at this point in the history
  • Loading branch information
jreback committed Oct 14, 2015
1 parent eda1924 commit 51a70dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pandas/core/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ def save(self):
close = False
else:
f = com._get_handle(self.path_or_buf, self.mode,
encoding=self.encoding,
encoding=self.encoding,
compression=self.compression)
close = True

Expand Down
38 changes: 20 additions & 18 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6618,31 +6618,25 @@ def test_to_csv_cols_reordering(self):
# GH3454
import pandas as pd

def _check_df(df,cols=None):
with ensure_clean() as path:
df.to_csv(path,columns = cols,engine='python')
rs_p = pd.read_csv(path,index_col=0)
df.to_csv(path,columns = cols,chunksize=chunksize)
rs_c = pd.read_csv(path,index_col=0)

if cols:
df = df[cols]
assert (rs_c.columns==rs_p.columns).all()
assert_frame_equal(df,rs_c,check_names=False)

chunksize=5
N = int(chunksize*2.5)

df= mkdf(N, 3)
cs = df.columns
cols = [cs[2],cs[0]]
_check_df(df,cols)

with ensure_clean() as path:
df.to_csv(path,columns = cols,chunksize=chunksize)
rs_c = pd.read_csv(path,index_col=0)

assert_frame_equal(df[cols],rs_c,check_names=False)

def test_to_csv_legacy_raises_on_dupe_cols(self):
df= mkdf(10, 3)
df.columns = ['a','a','b']
with ensure_clean() as path:
self.assertRaises(NotImplementedError,df.to_csv,path,engine='python')
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
self.assertRaises(NotImplementedError,df.to_csv,path,engine='python')

def test_to_csv_new_dupe_cols(self):
import pandas as pd
Expand Down Expand Up @@ -15198,10 +15192,14 @@ def test_to_csv_date_format(self):
pname = '__tmp_to_csv_date_format__'
with ensure_clean(pname) as path:
for engine in [None, 'python']:
w = FutureWarning if engine == 'python' else None

dt_index = self.tsframe.index
datetime_frame = DataFrame({'A': dt_index, 'B': dt_index.shift(1)}, index=dt_index)

datetime_frame.to_csv(path, date_format='%Y%m%d', engine=engine)
with tm.assert_produces_warning(w, check_stacklevel=False):
datetime_frame.to_csv(path, date_format='%Y%m%d', engine=engine)

# Check that the data was put in the specified format
test = read_csv(path, index_col=0)

Expand All @@ -15210,7 +15208,9 @@ def test_to_csv_date_format(self):

assert_frame_equal(test, datetime_frame_int)

datetime_frame.to_csv(path, date_format='%Y-%m-%d', engine=engine)
with tm.assert_produces_warning(w, check_stacklevel=False):
datetime_frame.to_csv(path, date_format='%Y-%m-%d', engine=engine)

# Check that the data was put in the specified format
test = read_csv(path, index_col=0)
datetime_frame_str = datetime_frame.applymap(lambda x: x.strftime('%Y-%m-%d'))
Expand All @@ -15221,7 +15221,8 @@ def test_to_csv_date_format(self):
# Check that columns get converted
datetime_frame_columns = datetime_frame.T

datetime_frame_columns.to_csv(path, date_format='%Y%m%d', engine=engine)
with tm.assert_produces_warning(w, check_stacklevel=False):
datetime_frame_columns.to_csv(path, date_format='%Y%m%d', engine=engine)

test = read_csv(path, index_col=0)

Expand All @@ -15235,7 +15236,8 @@ def test_to_csv_date_format(self):
nat_index = to_datetime(['NaT'] * 10 + ['2000-01-01', '1/1/2000', '1-1-2000'])
nat_frame = DataFrame({'A': nat_index}, index=nat_index)

nat_frame.to_csv(path, date_format='%Y-%m-%d', engine=engine)
with tm.assert_produces_warning(w, check_stacklevel=False):
nat_frame.to_csv(path, date_format='%Y-%m-%d', engine=engine)

test = read_csv(path, parse_dates=[0, 1], index_col=0)

Expand Down

0 comments on commit 51a70dc

Please sign in to comment.