/usr/lib/python3/dist-packages/pandas/io/tests/generate_legacy_pickles.py is in python3-pandas 0.13.1-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | """ self-contained to write legacy pickle files """
from __future__ import print_function
def _create_sp_series():
import numpy as np
from pandas import SparseSeries
nan = np.nan
# nan-based
arr = np.arange(15, dtype=np.float64)
index = np.arange(15)
arr[7:12] = nan
arr[-1:] = nan
bseries = SparseSeries(arr, kind='block')
bseries.name = 'bseries'
return bseries
def _create_sp_tsseries():
import numpy as np
from pandas import bdate_range, SparseTimeSeries
nan = np.nan
# nan-based
arr = np.arange(15, dtype=np.float64)
index = np.arange(15)
arr[7:12] = nan
arr[-1:] = nan
date_index = bdate_range('1/1/2011', periods=len(index))
bseries = SparseTimeSeries(arr, index=date_index, kind='block')
bseries.name = 'btsseries'
return bseries
def _create_sp_frame():
import numpy as np
from pandas import bdate_range, SparseDataFrame
nan = np.nan
data = {'A': [nan, nan, nan, 0, 1, 2, 3, 4, 5, 6],
'B': [0, 1, 2, nan, nan, nan, 3, 4, 5, 6],
'C': np.arange(10).astype(np.int64),
'D': [0, 1, 2, 3, 4, 5, nan, nan, nan, nan]}
dates = bdate_range('1/1/2011', periods=10)
return SparseDataFrame(data, index=dates)
def create_data():
""" create the pickle data """
import numpy as np
import pandas
from pandas import (Series,TimeSeries,DataFrame,Panel,
SparseSeries,SparseTimeSeries,SparseDataFrame,SparsePanel,
Index,MultiIndex,PeriodIndex,
date_range,bdate_range,Timestamp)
nan = np.nan
data = {
'A': [0., 1., 2., 3., np.nan],
'B': [0, 1, 0, 1, 0],
'C': ['foo1', 'foo2', 'foo3', 'foo4', 'foo5'],
'D': date_range('1/1/2009', periods=5),
'E' : [0., 1, Timestamp('20100101'),'foo',2.],
}
index = dict(int = Index(np.arange(10)),
date = date_range('20130101',periods=10))
mi = dict(reg2 = MultiIndex.from_tuples(tuple(zip(*[['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']])),
names=['first', 'second']))
series = dict(float = Series(data['A']),
int = Series(data['B']),
mixed = Series(data['E']),
ts = TimeSeries(np.arange(10).astype(np.int64),index=date_range('20130101',periods=10)),
mi = Series(np.arange(5).astype(np.float64),index=MultiIndex.from_tuples(tuple(zip(*[[1,1,2,2,2],
[3,4,3,4,5]])),
names=['one','two'])))
frame = dict(float = DataFrame(dict(A = series['float'], B = series['float'] + 1)),
int = DataFrame(dict(A = series['int'] , B = series['int'] + 1)),
mixed = DataFrame(dict([ (k,data[k]) for k in ['A','B','C','D']])),
mi = DataFrame(dict(A = np.arange(5).astype(np.float64), B = np.arange(5).astype(np.int64)),
index=MultiIndex.from_tuples(tuple(zip(*[['bar','bar','baz','baz','baz'],
['one','two','one','two','three']])),
names=['first','second'])))
panel = dict(float = Panel(dict(ItemA = frame['float'], ItemB = frame['float']+1)))
return dict( series = series,
frame = frame,
panel = panel,
index = index,
mi = mi,
sp_series = dict(float = _create_sp_series(),
ts = _create_sp_tsseries()),
sp_frame = dict(float = _create_sp_frame())
)
def write_legacy_pickles():
# force our cwd to be the first searched
import sys
sys.path.insert(0,'.')
import os, os.path
import numpy as np
import pandas
import pandas.util.testing as tm
import platform as pl
# make sure we are < 0.13 compat (in py3)
try:
from pandas.compat import zip, cPickle as pickle
except:
import pickle
sys_version = version = pandas.__version__
if len(sys.argv) < 2:
exit("{0} <version> <output_dir>".format(sys.argv[0]))
version = str(sys.argv[1])
output_dir = str(sys.argv[2])
print("This script generates a pickle file for the current arch, system, and python version")
print(" system version: {0}".format(sys_version))
print(" output version: {0}".format(version))
print(" output dir : {0}".format(output_dir))
# construct a reasonable platform name
f = '_'.join([ str(version), str(pl.machine()), str(pl.system().lower()), str(pl.python_version()) ])
pth = '{0}.pickle'.format(f)
fh = open(os.path.join(output_dir,pth),'wb')
pickle.dump(create_data(),fh,pickle.HIGHEST_PROTOCOL)
fh.close()
print("created pickle file: %s" % pth)
if __name__ == '__main__':
write_legacy_pickles()
|