1
- import pytest
2
-
3
- from warnings import catch_warnings
4
- import os
5
1
import datetime
2
+ from distutils .version import LooseVersion
6
3
import glob
4
+ import os
5
+ from warnings import catch_warnings
6
+
7
7
import numpy as np
8
- from distutils . version import LooseVersion
8
+ import pytest
9
9
10
- from pandas import compat
11
- from pandas .compat import u , PY3
12
- from pandas import (Series , DataFrame , Panel , MultiIndex , bdate_range ,
13
- date_range , period_range , Index , Categorical ,
14
- Period , Interval )
10
+ from pandas ._libs .tslib import iNaT
11
+ from pandas .compat import PY3 , u
15
12
from pandas .errors import PerformanceWarning
16
- from pandas .io .packers import to_msgpack , read_msgpack
17
- import pandas .util .testing as tm
18
- from pandas .util .testing import (ensure_clean ,
19
- assert_categorical_equal ,
20
- assert_frame_equal ,
21
- assert_index_equal ,
22
- assert_series_equal ,
23
- patch )
24
- from pandas .tests .test_panel import assert_panel_equal
25
13
26
14
import pandas
27
- from pandas import Timestamp , NaT
28
- from pandas ._libs .tslib import iNaT
15
+ from pandas import (
16
+ Categorical , DataFrame , Index , Interval , MultiIndex , NaT , Panel , Period ,
17
+ Series , Timestamp , bdate_range , compat , date_range , period_range )
18
+ from pandas .tests .test_panel import assert_panel_equal
19
+ import pandas .util .testing as tm
20
+ from pandas .util .testing import (
21
+ assert_categorical_equal , assert_frame_equal , assert_index_equal ,
22
+ assert_series_equal , ensure_clean )
23
+
24
+ from pandas .io .packers import read_msgpack , to_msgpack
29
25
30
26
nan = np .nan
31
27
@@ -660,7 +656,8 @@ def test_compression_blosc(self):
660
656
pytest .skip ('no blosc' )
661
657
self ._test_compression ('blosc' )
662
658
663
- def _test_compression_warns_when_decompress_caches (self , compress ):
659
+ def _test_compression_warns_when_decompress_caches (
660
+ self , monkeypatch , compress ):
664
661
not_garbage = []
665
662
control = [] # copied data
666
663
@@ -685,9 +682,9 @@ def decompress(ob):
685
682
np .dtype ('timedelta64[ns]' ): np .timedelta64 (1 , 'ns' ),
686
683
}
687
684
688
- with patch ( compress_module , 'decompress' , decompress ) , \
685
+ with monkeypatch . context () as m , \
689
686
tm .assert_produces_warning (PerformanceWarning ) as ws :
690
-
687
+ m . setattr ( compress_module , 'decompress' , decompress )
691
688
i_rec = self .encode_decode (self .frame , compress = compress )
692
689
for k in self .frame .keys ():
693
690
@@ -712,15 +709,17 @@ def decompress(ob):
712
709
# original buffers
713
710
assert buf == control_buf
714
711
715
- def test_compression_warns_when_decompress_caches_zlib (self ):
712
+ def test_compression_warns_when_decompress_caches_zlib (self , monkeypatch ):
716
713
if not _ZLIB_INSTALLED :
717
714
pytest .skip ('no zlib' )
718
- self ._test_compression_warns_when_decompress_caches ('zlib' )
715
+ self ._test_compression_warns_when_decompress_caches (
716
+ monkeypatch , 'zlib' )
719
717
720
- def test_compression_warns_when_decompress_caches_blosc (self ):
718
+ def test_compression_warns_when_decompress_caches_blosc (self , monkeypatch ):
721
719
if not _BLOSC_INSTALLED :
722
720
pytest .skip ('no blosc' )
723
- self ._test_compression_warns_when_decompress_caches ('blosc' )
721
+ self ._test_compression_warns_when_decompress_caches (
722
+ monkeypatch , 'blosc' )
724
723
725
724
def _test_small_strings_no_warn (self , compress ):
726
725
empty = np .array ([], dtype = 'uint8' )
0 commit comments