@@ -231,13 +231,33 @@ def test_standardize_mapping():
231231 columns = ['X' , 'Y' , 'Z' ]),
232232 Series (100 * [0.123456 , 0.234567 , 0.567567 ], name = 'X' )])
233233@pytest .mark .parametrize ('method' , ['to_pickle' , 'to_json' , 'to_csv' ])
234- def test_compression_size (obj , method , compression ):
235- if not compression :
236- pytest .skip ("only test compression case." )
234+ def test_compression_size (obj , method , compression_only ):
237235
238236 with tm .ensure_clean () as filename :
239- getattr (obj , method )(filename , compression = compression )
237+ getattr (obj , method )(filename , compression = compression_only )
240238 compressed = os .path .getsize (filename )
241239 getattr (obj , method )(filename , compression = None )
242240 uncompressed = os .path .getsize (filename )
243241 assert uncompressed > compressed
242+
243+
244+ @pytest .mark .parametrize ('obj' , [
245+ DataFrame (100 * [[0.123456 , 0.234567 , 0.567567 ],
246+ [12.32112 , 123123.2 , 321321.2 ]],
247+ columns = ['X' , 'Y' , 'Z' ]),
248+ Series (100 * [0.123456 , 0.234567 , 0.567567 ], name = 'X' )])
249+ @pytest .mark .parametrize ('method' , ['to_csv' ])
250+ def test_compression_size_fh (obj , method , compression_only ):
251+
252+ with tm .ensure_clean () as filename :
253+ with open (filename , 'w' ) as fh :
254+ getattr (obj , method )(fh , compression = compression_only )
255+ # GH 17778
256+ assert fh .closed
257+ compressed = os .path .getsize (filename )
258+ with tm .ensure_clean () as filename :
259+ with open (filename , 'w' ) as fh :
260+ getattr (obj , method )(fh , compression = None )
261+ assert not fh .closed
262+ uncompressed = os .path .getsize (filename )
263+ assert uncompressed > compressed
0 commit comments