@@ -304,47 +304,39 @@ def test_pickle_v0_15_2():
304
304
tm .assert_categorical_equal (cat , pd .read_pickle (pickle_path ))
305
305
306
306
307
- class TestPickleCompression (object ):
308
-
309
- def setup_class (self ):
310
- self .path = u'__%s__.pickle' % tm .rands (10 )
311
-
312
- def compression_explicit (self , compression ):
313
- # issue 11666
314
- if compression == 'xz' :
315
- tm ._skip_if_no_lzma ()
316
- with tm .ensure_clean (self .path ) as path :
307
+ # ---------------------
308
+ # test pickle compression
309
+ # ---------------------
310
+ def get_random_path ():
311
+ return u'__%s__.pickle' % tm .rands (10 )
312
+
313
+
314
+ @pytest .mark .parametrize ('compression' , [None , 'gzip' , 'bz2' , 'xz' ])
315
+ def test_compression_explicit (compression ):
316
+ # issue 11666
317
+ if compression == 'xz' :
318
+ tm ._skip_if_no_lzma ()
319
+ with tm .ensure_clean (get_random_path ()) as path :
320
+ df = tm .makeDataFrame ()
321
+ df .to_pickle (path , compression = compression )
322
+ df2 = pd .read_pickle (path , compression = compression )
323
+ tm .assert_frame_equal (df , df2 )
324
+
325
+
326
+ @pytest .mark .parametrize ('compression' , ['' , 'None' , 'bad' , '7z' ])
327
+ def test_compression_explicit_bad (compression ):
328
+ with tm .assertRaisesRegexp (ValueError ,
329
+ "Unrecognized compression type" ):
330
+ with tm .ensure_clean (get_random_path ()) as path :
317
331
df = tm .makeDataFrame ()
318
332
df .to_pickle (path , compression = compression )
319
- df2 = pd .read_pickle (path , compression = compression )
320
- tm .assert_frame_equal (df , df2 )
321
-
322
- def test_compression_explicit (self ):
323
- compressions = [None , 'gzip' , 'bz2' , 'xz' ]
324
- for c in compressions :
325
- yield self .compression_explicit , c
326
-
327
- def compression_explicit_bad (self , compression ):
328
- with tm .assertRaisesRegexp (ValueError ,
329
- "Unrecognized compression type" ):
330
- with tm .ensure_clean (self .path ) as path :
331
- df = tm .makeDataFrame ()
332
- df .to_pickle (path , compression = compression )
333
-
334
- def test_compression_explicit_bad (self ):
335
- compressions = ['' , 'None' , 'bad' , '7z' ]
336
- for c in compressions :
337
- yield self .compression_explicit_bad , c
338
-
339
- def compression_infer (self , ext ):
340
- if ext == '.xz' :
341
- tm ._skip_if_no_lzma ()
342
- with tm .ensure_clean (self .path + ext ) as path :
343
- df = tm .makeDataFrame ()
344
- df .to_pickle (path )
345
- tm .assert_frame_equal (df , pd .read_pickle (path ))
346
333
347
- def test_compression_infer (self ):
348
- extensions = ['' , '.gz' , '.bz2' , '.xz' , '.no_compress' ]
349
- for ext in extensions :
350
- yield self .compression_infer , ext
334
+
335
+ @pytest .mark .parametrize ('ext' , ['' , '.gz' , '.bz2' , '.xz' , '.no_compress' ])
336
+ def test_compression_infer (ext ):
337
+ if ext == '.xz' :
338
+ tm ._skip_if_no_lzma ()
339
+ with tm .ensure_clean (get_random_path () + ext ) as path :
340
+ df = tm .makeDataFrame ()
341
+ df .to_pickle (path )
342
+ tm .assert_frame_equal (df , pd .read_pickle (path ))
0 commit comments