Skip to content

Commit f600e20

Browse files
committed
ENH: added legacy pickel generation/testing suppport
TST: added io/tests/test_pickle.py to test stored pickles added io/tests/generate_legacy_pickles.py to create legacy pickles on various arch and sytems (need contributions) added some sample pickles for 0.10.1/0.11.0
1 parent ea6d721 commit f600e20

File tree

5 files changed

+105
-8
lines changed

5 files changed

+105
-8
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
""" self-contained to write legacy pickle files """
2+
3+
def create_data():
4+
""" create the pickle data """
5+
6+
import numpy as np
7+
import pandas
8+
from pandas import (Series,DataFrame,Panel,
9+
SparseSeries,SparseDataFrame,SparsePanel,
10+
Index,MultiIndex,PeriodIndex,
11+
date_range,Timestamp)
12+
13+
data = {
14+
'A': [0., 1., 2., 3., np.nan],
15+
'B': [0, 1, 0, 1, 0],
16+
'C': ['foo1', 'foo2', 'foo3', 'foo4', 'foo5'],
17+
'D': date_range('1/1/2009', periods=5),
18+
'E' : [0., 1, Timestamp('20100101'),'foo',2.],
19+
}
20+
21+
series = dict(float = Series(data['A']),
22+
int = Series(data['B']),
23+
mixed = Series(data['E']))
24+
frame = dict(float = DataFrame(dict(A = series['float'], B = series['float'] + 1)),
25+
int = DataFrame(dict(A = series['int'] , B = series['int'] + 1)),
26+
mixed = DataFrame(dict([ (k,data[k]) for k in ['A','B','C','D']])))
27+
panel = dict(float = Panel(dict(ItemA = frame['float'], ItemB = frame['float']+1)))
28+
29+
return dict( series = series,
30+
frame = frame,
31+
panel = panel )
32+
33+
def write_legacy_pickles():
34+
35+
# force our cwd to be the first searched
36+
import sys
37+
sys.path.insert(0,'.')
38+
39+
import os
40+
import numpy as np
41+
import pandas
42+
import pandas.util.testing as tm
43+
import platform as pl
44+
import cPickle as pickle
45+
46+
print "This script generates a pickle file for the current arch, system, and python version"
47+
48+
base_dir, _ = os.path.split(os.path.abspath(__file__))
49+
base_dir = os.path.join(base_dir,'data/legacy_pickle')
50+
51+
# could make this a parameter?
52+
version = None
53+
54+
55+
if version is None:
56+
version = pandas.__version__
57+
pth = os.path.join(base_dir, str(version))
58+
try:
59+
os.mkdir(pth)
60+
except:
61+
pass
62+
63+
# construct a reasonable platform name
64+
f = '_'.join([ str(pl.machine()), str(pl.system().lower()), str(pl.python_version()) ])
65+
pth = os.path.abspath(os.path.join(pth,'%s.pickle' % f))
66+
67+
fh = open(pth,'wb')
68+
pickle.dump(create_data(),fh,pickle.HIGHEST_PROTOCOL)
69+
fh.close()
70+
71+
print "created pickle file: %s" % pth
72+
73+
if __name__ == '__main__':
74+
write_legacy_pickles()

pandas/io/tests/test_pickle.py

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# pylint: disable=E1101,E1103,W0232
22

3+
""" manage legacy pickle tests """
4+
35
from datetime import datetime, timedelta
46
import operator
57
import pickle
@@ -8,22 +10,43 @@
810
import os
911

1012
import numpy as np
11-
from numpy.testing import assert_array_equal
12-
from pandas.util.testing import assert_almost_equal
13-
from pandas.util import py3compat
14-
import pandas.core.common as com
15-
1613
import pandas.util.testing as tm
1714
import pandas as pd
1815

1916
class TestPickle(unittest.TestCase):
2017
_multiprocess_can_split_ = True
2118

2219
def setUp(self):
23-
pass
20+
from pandas.io.tests.generate_legacy_pickles import create_data
21+
self.data = create_data()
22+
23+
def compare(self, vf):
24+
25+
fh = open(vf,'rb')
26+
data = pickle.load(fh)
27+
fh.close()
28+
29+
for typ, dv in data.items():
30+
for dt, result in dv.items():
31+
32+
expected = self.data[typ][dt]
33+
34+
comparator = getattr(tm,"assert_%s_equal" % typ)
35+
comparator(result,expected)
36+
37+
def test_read_pickles_0_10_1(self):
38+
39+
pth = tm.get_data_path('legacy_pickle/0.10.1')
40+
for f in os.listdir(pth):
41+
vf = os.path.join(pth,f)
42+
self.compare(vf)
43+
44+
def test_read_pickles_0_11_0(self):
2445

25-
#def test_hash_error(self):
26-
# self.assertRaises(TypeError, hash, self.strIndex)
46+
pth = tm.get_data_path('legacy_pickle/0.11.0')
47+
for f in os.listdir(pth):
48+
vf = os.path.join(pth,f)
49+
self.compare(vf)
2750

2851
if __name__ == '__main__':
2952
import nose

0 commit comments

Comments
 (0)