Skip to content

Commit 5667a3a

Browse files
committed
TST: fix up compression tests / docs
1 parent 0cfc950 commit 5667a3a

File tree

3 files changed

+208
-176
lines changed

3 files changed

+208
-176
lines changed

doc/source/io.rst

+36-19
Original file line numberDiff line numberDiff line change
@@ -3042,40 +3042,57 @@ any pickled pandas object (or any other pickled object) from file:
30423042
See `this question <http://stackoverflow.com/questions/20444593/pandas-compiled-from-source-default-pickle-behavior-changed>`__
30433043
for a detailed explanation.
30443044

3045-
.. note::
3046-
3047-
These methods were previously ``pd.save`` and ``pd.load``, prior to 0.12.0, and are now deprecated.
3048-
30493045
.. _io.pickle.compression:
30503046

3051-
Read/Write compressed pickle files
3052-
''''''''''''''
3047+
Compressed pickle files
3048+
'''''''''''''''''''''''
30533049

30543050
.. versionadded:: 0.20.0
30553051

30563052
:func:`read_pickle`, :meth:`DataFame.to_pickle` and :meth:`Series.to_pickle` can read
3057-
and write compressed pickle files. Compression types of ``gzip``, ``bz2``, ``xz`` supports
3058-
both read and write. ``zip`` file supports read only and must contain only one data file
3053+
and write compressed pickle files. The compression types of ``gzip``, ``bz2``, ``xz`` are supported for reading and writing.
3054+
`zip`` file supports read only and must contain only one data file
30593055
to be read in.
3060-
Compression type can be an explicitely parameter or be inferred from the file extension.
3056+
3057+
The compression type can be an explicit parameter or be inferred from the file extension.
30613058
If 'infer', then use ``gzip``, ``bz2``, ``zip``, or ``xz`` if filename ends in ``'.gz'``, ``'.bz2'``, ``'.zip'``, or
30623059
``'.xz'``, respectively.
30633060

30643061
.. ipython:: python
30653062
30663063
df = pd.DataFrame({
30673064
'A': np.random.randn(1000),
3068-
'B': np.random.randn(1000),
3069-
'C': np.random.randn(1000)})
3070-
df.to_pickle("data.pkl.compress", compression="gzip") # explicit compression type
3071-
df.to_pickle("data.pkl.xz", compression="infer") # infer compression type from extension
3072-
df.to_pickle("data.pkl.gz") # default, using "infer"
3073-
df["A"].to_pickle("s1.pkl.bz2")
3065+
'B': 'foo',
3066+
'C': pd.date_range('20130101', periods=1000, freq='s')})
3067+
df
3068+
3069+
Using an explicit compression type
3070+
3071+
.. ipython:: python
30743072
3075-
df = pd.read_pickle("data.pkl.compress", compression="gzip")
3076-
df = pd.read_pickle("data.pkl.xz", compression="infer")
3077-
df = pd.read_pickle("data.pkl.gz")
3078-
s = pd.read_pickle("s1.pkl.bz2")
3073+
df.to_pickle("data.pkl.compress", compression="gzip")
3074+
rt = pd.read_pickle("data.pkl.compress", compression="gzip")
3075+
rt
3076+
3077+
Inferring compression type from the extension
3078+
3079+
.. ipython:: python
3080+
3081+
df.to_pickle("data.pkl.xz", compression="infer")
3082+
rt = pd.read_pickle("data.pkl.xz", compression="infer")
3083+
rt
3084+
3085+
The default is to 'infer
3086+
3087+
.. ipython:: python
3088+
3089+
df.to_pickle("data.pkl.gz")
3090+
rt = pd.read_pickle("data.pkl.gz")
3091+
rt
3092+
3093+
df["A"].to_pickle("s1.pkl.bz2")
3094+
rt = pd.read_pickle("s1.pkl.bz2")
3095+
rt
30793096
30803097
.. ipython:: python
30813098
:suppress:

doc/source/whatsnew/v0.20.0.txt

+29-11
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,41 @@ Pickle file I/O now supports compression
102102
:func:`read_pickle`, :meth:`DataFame.to_pickle` and :meth:`Series.to_pickle`
103103
can now read from and write to compressed pickle files. Compression methods
104104
can be an explicit parameter or be inferred from the file extension.
105-
See :ref:`Read/Write compressed pickle files <io.pickle.compression>`
105+
See :ref:`the docs here <io.pickle.compression>`
106106

107107
.. ipython:: python
108108

109109
df = pd.DataFrame({
110110
'A': np.random.randn(1000),
111-
'B': np.random.randn(1000),
112-
'C': np.random.randn(1000)})
113-
df.to_pickle("data.pkl.compress", compression="gzip") # explicit compression type
114-
df.to_pickle("data.pkl.xz", compression="infer") # infer compression type from extension
115-
df.to_pickle("data.pkl.gz") # default, using "infer"
116-
df["A"].to_pickle("s1.pkl.bz2")
111+
'B': 'foo',
112+
'C': pd.date_range('20130101', periods=1000, freq='s')})
113+
114+
Using an explicit compression type
115+
116+
.. ipython:: python
117117

118-
df = pd.read_pickle("data.pkl.compress", compression="gzip")
119-
df = pd.read_pickle("data.pkl.xz", compression="infer")
120-
df = pd.read_pickle("data.pkl.gz")
121-
s = pd.read_pickle("s1.pkl.bz2")
118+
df.to_pickle("data.pkl.compress", compression="gzip")
119+
rt = pd.read_pickle("data.pkl.compress", compression="gzip")
120+
rt
121+
122+
Inferring compression type from the extension
123+
124+
.. ipython:: python
125+
126+
df.to_pickle("data.pkl.xz", compression="infer")
127+
rt = pd.read_pickle("data.pkl.xz", compression="infer")
128+
rt
129+
130+
The default is to 'infer
131+
132+
.. ipython:: python
133+
134+
df.to_pickle("data.pkl.gz")
135+
rt = pd.read_pickle("data.pkl.gz")
136+
rt
137+
df["A"].to_pickle("s1.pkl.bz2")
138+
rt = pd.read_pickle("s1.pkl.bz2")
139+
rt
122140

123141
.. ipython:: python
124142
:suppress:

0 commit comments

Comments
 (0)