Skip to content

Commit 886c3c7

Browse files
author
y-p
committed
TST: Test to_csv in more cases and faster
1 parent a12d480 commit 886c3c7

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

pandas/tests/test_frame.py

+32-16
Original file line numberDiff line numberDiff line change
@@ -3402,7 +3402,7 @@ def test_from_records_misc_brokenness(self):
34023402
df2_obj = DataFrame.from_records(rows, columns=['date', 'test'])
34033403
results = df2_obj.get_dtype_counts()
34043404
expected = Series({ 'datetime64[ns]' : 1, 'int64' : 1 })
3405-
3405+
34063406
def test_to_records_floats(self):
34073407
df = DataFrame(np.random.rand(10, 10))
34083408
df.to_records()
@@ -4498,12 +4498,14 @@ def test_to_csv_from_csv(self):
44984498
def test_to_csv_moar(self):
44994499
from pandas.util.testing import makeCustomDataframe as mkdf
45004500
path = '__tmp_to_csv_moar__'
4501+
chunksize=1000
4502+
45014503
def _do_test(df,path,r_dtype=None,c_dtype=None,rnlvl=None,cnlvl=None,
45024504
dupe_col=False):
45034505

45044506
with ensure_clean(path) as path:
4505-
df.to_csv(path,encoding='utf8')
4506-
recons = DataFrame.from_csv(path)
4507+
df.to_csv(path,encoding='utf8',chunksize=chunksize)
4508+
recons = DataFrame.from_csv(path,parse_dates=False)
45074509

45084510
def _to_uni(x):
45094511
if not isinstance(x,unicode):
@@ -4561,13 +4563,34 @@ def stuple_to_tuple(x):
45614563
recons.columns = np.array(recons.columns,dtype=c_dtype )
45624564
df.columns = np.array(df.columns,dtype=c_dtype )
45634565

4564-
assert_frame_equal(df, recons,check_names=False)
4566+
assert_frame_equal(df, recons,check_names=False,check_less_precise=True)
45654567

45664568

45674569
N = 100
45684570

4571+
for ncols in [128]:
4572+
base = int((chunksize// ncols or 1) or 1)
4573+
for nrows in [2,10,N-1,N,N+1,N+2,2*N-2,2*N-1,2*N,2*N+1,2*N+2,
4574+
base-1,base,base+1]:
4575+
_do_test(mkdf(nrows, ncols,r_idx_type='dt',
4576+
c_idx_type='s'),path, 'dt','s')
4577+
4578+
# pending GH3173
4579+
# for r_idx_type in ['i', 'f','s','u']:
4580+
# for c_idx_type in ['i', 'f','s','u','dt']:
4581+
4582+
for r_idx_type in ['i','s','u']:
4583+
for c_idx_type in ['i', 's','u','dt']:
4584+
for ncols in [1,2,128]:
4585+
base = int((chunksize// ncols or 1) or 1)
4586+
for nrows in [2,10,N-1,N,N+1,N+2,2*N-2,2*N-1,2*N,2*N+1,2*N+2,
4587+
base-1,base,base+1]:
4588+
_do_test(mkdf(nrows, ncols,r_idx_type=r_idx_type,
4589+
c_idx_type=c_idx_type),path,r_idx_type,c_idx_type)
4590+
4591+
45694592
for ncols in [1,10,30]:
4570-
base = int((100000/ ncols or 1) or 1)
4593+
base = int((chunksize// ncols or 1) or 1)
45714594
for nrows in [10,N-2,N-1,N,N+1,N+2,2*N-2,2*N-1,2*N,2*N+1,2*N+2,
45724595
base-1,base,base+1]:
45734596
print( nrows,ncols)
@@ -4585,18 +4608,11 @@ def stuple_to_tuple(x):
45854608
df.columns=cols
45864609
_do_test(df,path,dupe_col=True)
45874610

4588-
for r_idx_type in ['i', 'f','s','u','dt']:
4589-
for c_idx_type in ['i', 'f','s','u','dt']:
4590-
print(r_idx_type,c_idx_type)
4591-
_do_test(mkdf(100, 1,r_idx_type=r_idx_type,
4592-
c_idx_type=c_idx_type),path,r_idx_type,c_idx_type)
4593-
_do_test(mkdf(100, 2,r_idx_type=r_idx_type,
4594-
c_idx_type=c_idx_type),path,r_idx_type,c_idx_type)
45954611

45964612
_do_test(DataFrame(index=range(10)),path)
4597-
_do_test(mkdf(50001, 2,r_idx_nlevels=2),path,rnlvl=2)
4613+
_do_test(mkdf(chunksize//2+1, 2,r_idx_nlevels=2),path,rnlvl=2)
45984614
for ncols in [2,10,30]:
4599-
base = int(100000/ncols)
4615+
base = int(chunksize//ncols)
46004616
for nrows in [10,N-2,N-1,N,N+1,N+2,2*N-2,2*N-1,2*N,2*N+1,2*N+2,
46014617
base-1,base,base+1]:
46024618
print(nrows, ncols)
@@ -4709,7 +4725,7 @@ def test_to_csv_boundry_conditions(self):
47094725
assert_frame_equal(rs, df)
47104726

47114727
df = makeTimeDataFrame(25001)
4712-
df.to_csv(path)
4728+
df.to_csv(path)
47134729
rs = pan.read_csv(path, index_col=0, parse_dates=True)
47144730
assert_frame_equal(rs, df)
47154731

@@ -4799,7 +4815,7 @@ def test_to_csv_unicode(self):
47994815

48004816
df = DataFrame({u'c/\u03c3': [1, 2, 3]})
48014817
with ensure_clean() as path:
4802-
4818+
48034819
df.to_csv(path, encoding='UTF-8')
48044820
df2 = pan.read_csv(path, index_col=0, encoding='UTF-8')
48054821
assert_frame_equal(df, df2)

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ changedir = {envdir}
2121

2222
commands =
2323
# TODO: --exe because of GH #761
24-
{envbindir}/nosetests --exe pandas.tests
24+
{envbindir}/nosetests --exe pandas.tests -A "not network"
2525
# cleanup the temp. build dir created by the tox build
2626
/bin/rm -rf {toxinidir}/build
2727

tox_prll.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ changedir = {envdir}
2222

2323
commands =
2424
# TODO: --exe because of GH #761
25-
{envbindir}/nosetests --exe pandas.tests
25+
{envbindir}/nosetests --exe pandas.tests -A "not network"
2626
# cleanup the temp. build dir created by the tox build
2727
/bin/rm -rf {toxinidir}/build
2828

0 commit comments

Comments
 (0)