| 
1 | 1 | # -*- coding: utf-8 -*-  | 
2 | 2 | 
 
  | 
3 | 3 | import pytest  | 
 | 4 | +import os  | 
4 | 5 | import collections  | 
5 | 6 | from functools import partial  | 
6 | 7 | 
 
  | 
7 | 8 | import numpy as np  | 
8 | 9 | 
 
  | 
9 |  | -from pandas import Series, Timestamp  | 
 | 10 | +import pandas as pd  | 
 | 11 | +from pandas import Series, DataFrame, Timestamp  | 
10 | 12 | from pandas.compat import range, lmap  | 
11 | 13 | import pandas.core.common as com  | 
12 | 14 | from pandas.core import ops  | 
@@ -222,3 +224,28 @@ def test_standardize_mapping():  | 
222 | 224 | 
 
  | 
223 | 225 |     dd = collections.defaultdict(list)  | 
224 | 226 |     assert isinstance(com.standardize_mapping(dd), partial)  | 
 | 227 | + | 
 | 228 | + | 
 | 229 | +@pytest.mark.parametrize('method', ['to_pickle', 'to_json', 'to_csv'])  | 
 | 230 | +def test_compression_size(method, compression):  | 
 | 231 | + | 
 | 232 | +    df = pd.concat(100 * [DataFrame([[0.123456, 0.234567, 0.567567],  | 
 | 233 | +                                     [12.32112, 123123.2, 321321.2]],  | 
 | 234 | +                                    columns=['X', 'Y', 'Z'])],  | 
 | 235 | +                   ignore_index=True)  | 
 | 236 | +    s = df.iloc[:, 0]  | 
 | 237 | + | 
 | 238 | +    with tm.ensure_clean() as filename:  | 
 | 239 | +        getattr(df, method)(filename, compression=compression)  | 
 | 240 | +        file_size = os.path.getsize(filename)  | 
 | 241 | +        getattr(df, method)(filename, compression=None)  | 
 | 242 | +        uncompressed_file_size = os.path.getsize(filename)  | 
 | 243 | +        if compression:  | 
 | 244 | +            assert uncompressed_file_size > file_size  | 
 | 245 | + | 
 | 246 | +        getattr(s, method)(filename, compression=compression)  | 
 | 247 | +        file_size = os.path.getsize(filename)  | 
 | 248 | +        getattr(s, method)(filename, compression=None)  | 
 | 249 | +        uncompressed_file_size = os.path.getsize(filename)  | 
 | 250 | +        if compression:  | 
 | 251 | +            assert uncompressed_file_size > file_size  | 
0 commit comments