1
1
# pylint: disable-msg=W0612,E1101
2
+ import sys
2
3
import nose
3
4
import itertools
4
5
import warnings
19
20
assert_frame_equal , assert_panel_equal ,
20
21
assert_attr_equal )
21
22
from pandas import concat
23
+ from pandas .io .common import PerformanceWarning
22
24
23
25
import pandas .util .testing as tm
24
26
from pandas import date_range
@@ -1489,8 +1491,6 @@ def test_loc_multiindex(self):
1489
1491
assert_series_equal (result , expected )
1490
1492
1491
1493
def test_multiindex_perf_warn (self ):
1492
- import sys
1493
- from pandas .io .common import PerformanceWarning
1494
1494
1495
1495
if sys .version_info < (2 , 7 ):
1496
1496
raise nose .SkipTest ('python version < 2.7' )
@@ -1499,14 +1499,18 @@ def test_multiindex_perf_warn(self):
1499
1499
'joe' :['x' , 'x' , 'z' , 'y' ],
1500
1500
'jolie' :np .random .rand (4 )}).set_index (['jim' , 'joe' ])
1501
1501
1502
- with tm .assert_produces_warning (PerformanceWarning ):
1502
+ with tm .assert_produces_warning (PerformanceWarning , clear = [ pd . core . index ] ):
1503
1503
_ = df .loc [(1 , 'z' )]
1504
1504
1505
1505
df = df .iloc [[2 ,1 ,3 ,0 ]]
1506
1506
with tm .assert_produces_warning (PerformanceWarning ):
1507
1507
_ = df .loc [(0 ,)]
1508
1508
1509
1509
def test_multiindex_get_loc (self ): # GH7724, GH2646
1510
+
1511
+ # ignore the warning here
1512
+ warnings .simplefilter ('ignore' , PerformanceWarning )
1513
+
1510
1514
# test indexing into a multi-index before & past the lexsort depth
1511
1515
from numpy .random import randint , choice , randn
1512
1516
cols = ['jim' , 'joe' , 'jolie' , 'joline' , 'jolia' ]
@@ -1568,6 +1572,9 @@ def loop(mi, df, keys):
1568
1572
assert not mi .index .lexsort_depth < i
1569
1573
loop (mi , df , keys )
1570
1574
1575
+ # restore
1576
+ warnings .simplefilter ('always' , PerformanceWarning )
1577
+
1571
1578
def test_series_getitem_multiindex (self ):
1572
1579
1573
1580
# GH 6018
@@ -1621,6 +1628,8 @@ def test_ix_general(self):
1621
1628
'year' : {0 : 2012 , 1 : 2011 , 2 : 2012 , 3 : 2012 , 4 : 2012 }}
1622
1629
df = DataFrame (data ).set_index (keys = ['col' , 'year' ])
1623
1630
key = 4.0 , 2012
1631
+
1632
+ # emits a PerformanceWarning, ok
1624
1633
tm .assert_frame_equal (df .ix [key ], df .iloc [2 :])
1625
1634
1626
1635
# this is ok
0 commit comments