11# pylint: disable-msg=W0612,E1101
2+ import sys
23import nose
34import itertools
45import warnings
1920 assert_frame_equal , assert_panel_equal ,
2021 assert_attr_equal )
2122from pandas import concat
23+ from pandas .io .common import PerformanceWarning
2224
2325import pandas .util .testing as tm
2426from pandas import date_range
@@ -1489,8 +1491,6 @@ def test_loc_multiindex(self):
14891491 assert_series_equal (result , expected )
14901492
14911493 def test_multiindex_perf_warn (self ):
1492- import sys
1493- from pandas .io .common import PerformanceWarning
14941494
14951495 if sys .version_info < (2 , 7 ):
14961496 raise nose .SkipTest ('python version < 2.7' )
@@ -1499,14 +1499,18 @@ def test_multiindex_perf_warn(self):
14991499 'joe' :['x' , 'x' , 'z' , 'y' ],
15001500 'jolie' :np .random .rand (4 )}).set_index (['jim' , 'joe' ])
15011501
1502- with tm .assert_produces_warning (PerformanceWarning ):
1502+ with tm .assert_produces_warning (PerformanceWarning , clear = [ pd . core . index ] ):
15031503 _ = df .loc [(1 , 'z' )]
15041504
15051505 df = df .iloc [[2 ,1 ,3 ,0 ]]
15061506 with tm .assert_produces_warning (PerformanceWarning ):
15071507 _ = df .loc [(0 ,)]
15081508
15091509 def test_multiindex_get_loc (self ): # GH7724, GH2646
1510+
1511+ # ignore the warning here
1512+ warnings .simplefilter ('ignore' , PerformanceWarning )
1513+
15101514 # test indexing into a multi-index before & past the lexsort depth
15111515 from numpy .random import randint , choice , randn
15121516 cols = ['jim' , 'joe' , 'jolie' , 'joline' , 'jolia' ]
@@ -1568,6 +1572,9 @@ def loop(mi, df, keys):
15681572 assert not mi .index .lexsort_depth < i
15691573 loop (mi , df , keys )
15701574
1575+ # restore
1576+ warnings .simplefilter ('always' , PerformanceWarning )
1577+
15711578 def test_series_getitem_multiindex (self ):
15721579
15731580 # GH 6018
@@ -1621,6 +1628,8 @@ def test_ix_general(self):
16211628 'year' : {0 : 2012 , 1 : 2011 , 2 : 2012 , 3 : 2012 , 4 : 2012 }}
16221629 df = DataFrame (data ).set_index (keys = ['col' , 'year' ])
16231630 key = 4.0 , 2012
1631+
1632+ # emits a PerformanceWarning, ok
16241633 tm .assert_frame_equal (df .ix [key ], df .iloc [2 :])
16251634
16261635 # this is ok
0 commit comments