|
| 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() |
0 commit comments