|
1 | 1 | """ |
2 | 2 | Misc tools for implementing data structures |
3 | 3 | """ |
4 | | -# XXX: HACK for NumPy 1.5.1 to suppress warnings |
5 | | -try: |
6 | | - import cPickle as pickle |
7 | | -except ImportError: # pragma: no cover |
8 | | - import pickle |
9 | 4 |
|
10 | 5 | import itertools |
11 | 6 | from datetime import datetime |
@@ -1668,49 +1663,6 @@ def _all_none(*args): |
1668 | 1663 | return True |
1669 | 1664 |
|
1670 | 1665 |
|
1671 | | -def save(obj, path): |
1672 | | - """ |
1673 | | - Pickle (serialize) object to input file path |
1674 | | -
|
1675 | | - Parameters |
1676 | | - ---------- |
1677 | | - obj : any object |
1678 | | - path : string |
1679 | | - File path |
1680 | | - """ |
1681 | | - f = open(path, 'wb') |
1682 | | - try: |
1683 | | - pickle.dump(obj, f, protocol=pickle.HIGHEST_PROTOCOL) |
1684 | | - finally: |
1685 | | - f.close() |
1686 | | - |
1687 | | - |
1688 | | -def load(path): |
1689 | | - """ |
1690 | | - Load pickled pandas object (or any other pickled object) from the specified |
1691 | | - file path |
1692 | | -
|
1693 | | - Warning: Loading pickled data received from untrusted sources can be unsafe. |
1694 | | - See: http://docs.python.org/2.7/library/pickle.html |
1695 | | -
|
1696 | | - Parameters |
1697 | | - ---------- |
1698 | | - path : string |
1699 | | - File path |
1700 | | -
|
1701 | | - Returns |
1702 | | - ------- |
1703 | | - unpickled : type of object stored in file |
1704 | | - """ |
1705 | | - try: |
1706 | | - with open(path,'rb') as fh: |
1707 | | - return pickle.load(fh) |
1708 | | - except: |
1709 | | - if not py3compat.PY3: |
1710 | | - raise |
1711 | | - with open(path,'rb') as fh: |
1712 | | - return pickle.load(fh, encoding='latin1') |
1713 | | - |
1714 | 1666 | class UTF8Recoder: |
1715 | 1667 | """ |
1716 | 1668 | Iterator that reads an encoded stream and reencodes the input to UTF-8 |
@@ -2109,3 +2061,40 @@ def console_encode(object, **kwds): |
2109 | 2061 | """ |
2110 | 2062 | return pprint_thing_encoded(object, |
2111 | 2063 | get_option("display.encoding")) |
| 2064 | + |
| 2065 | +def load(path): # TODO remove in 0.12 |
| 2066 | + """ |
| 2067 | + Load pickled pandas object (or any other pickled object) from the specified |
| 2068 | + file path |
| 2069 | +
|
| 2070 | + Warning: Loading pickled data received from untrusted sources can be unsafe. |
| 2071 | + See: http://docs.python.org/2.7/library/pickle.html |
| 2072 | +
|
| 2073 | + Parameters |
| 2074 | + ---------- |
| 2075 | + path : string |
| 2076 | + File path |
| 2077 | +
|
| 2078 | + Returns |
| 2079 | + ------- |
| 2080 | + unpickled : type of object stored in file |
| 2081 | + """ |
| 2082 | + import warnings |
| 2083 | + warnings.warn("load is deprecated, use read_pickle", FutureWarning) |
| 2084 | + from pandas.io.pickle import read_pickle |
| 2085 | + return read_pickle(path) |
| 2086 | + |
| 2087 | +def save(obj, path): # TODO remove in 0.12 |
| 2088 | + ''' |
| 2089 | + Pickle (serialize) object to input file path |
| 2090 | +
|
| 2091 | + Parameters |
| 2092 | + ---------- |
| 2093 | + obj : any object |
| 2094 | + path : string |
| 2095 | + File path |
| 2096 | + ''' |
| 2097 | + import warnings |
| 2098 | + warnings.warn("save is deprecated, use obj.to_pickle", FutureWarning) |
| 2099 | + from pandas.io.pickle import to_pickle |
| 2100 | + return to_pickle(obj, path) |
0 commit comments