@@ -575,7 +575,7 @@ def test_grouper_column_and_index_sugar(self):
575575 expected = df_single .groupby (pd .Grouper (level = 'inner' )).mean ()
576576 assert_frame_equal (result , expected )
577577
578- def test_grouper_column_takes_precedence_over_level (self ):
578+ def test_grouper_column_takes_precedence_over_level_with_warning (self ):
579579 # GH 5677, when a string passed as the `by` parameter
580580 # matches a column and an index level the column takes
581581 # precedence
@@ -592,74 +592,94 @@ def test_grouper_column_takes_precedence_over_level(self):
592592 df_single_both = df_multi_both .reset_index ('outer' )
593593
594594 # Group MultiIndex by single key
595- result = df_multi_both .groupby ('inner' ).mean ()
596- expected = df_multi_both .groupby (pd .Grouper (key = 'inner' )).mean ()
595+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
596+ result = df_multi_both .groupby ('inner' ).mean ()
597+
598+ expected = df_multi_both .groupby ([pd .Grouper (key = 'inner' )]).mean ()
599+
597600 assert_frame_equal (result , expected )
598601 not_expected = df_multi_both .groupby (pd .Grouper (level = 'inner' )).mean ()
599- assert not result .index .equals (not_expected .index )
602+ self . assertFalse ( result .index .equals (not_expected .index ) )
600603
601604 # Group single Index by single key
602- result = df_single_both .groupby ('inner' ).mean ()
603- expected = df_single_both .groupby (pd .Grouper (key = 'inner' )).mean ()
605+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
606+ result = df_single_both .groupby ('inner' ).mean ()
607+
608+ expected = df_single_both .groupby ([pd .Grouper (key = 'inner' )]).mean ()
609+
604610 assert_frame_equal (result , expected )
605611 not_expected = df_single_both .groupby (pd .Grouper (level = 'inner' )).mean ()
606- assert not result .index .equals (not_expected .index )
612+ self . assertFalse ( result .index .equals (not_expected .index ) )
607613
608614 # Group MultiIndex by single key list
609- result = df_multi_both .groupby (['inner' ]).mean ()
610- expected = df_multi_both .groupby (pd .Grouper (key = 'inner' )).mean ()
615+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
616+ result = df_multi_both .groupby (['inner' ]).mean ()
617+
618+ expected = df_multi_both .groupby ([pd .Grouper (key = 'inner' )]).mean ()
619+
611620 assert_frame_equal (result , expected )
612621 not_expected = df_multi_both .groupby (pd .Grouper (level = 'inner' )).mean ()
613- assert not result .index .equals (not_expected .index )
622+ self . assertFalse ( result .index .equals (not_expected .index ) )
614623
615624 # Group single Index by single key list
616- result = df_single_both .groupby (['inner' ]).mean ()
617- expected = df_single_both .groupby (pd .Grouper (key = 'inner' )).mean ()
625+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
626+ result = df_single_both .groupby (['inner' ]).mean ()
627+
628+ expected = df_single_both .groupby ([pd .Grouper (key = 'inner' )]).mean ()
629+
618630 assert_frame_equal (result , expected )
619631 not_expected = df_single_both .groupby (pd .Grouper (level = 'inner' )).mean ()
620- assert not result .index .equals (not_expected .index )
632+ self . assertFalse ( result .index .equals (not_expected .index ) )
621633
622634 # Group MultiIndex by two keys (1)
623- result = df_multi_both .groupby (['B' , 'inner' ]).mean ()
635+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
636+ result = df_multi_both .groupby (['B' , 'inner' ]).mean ()
637+
624638 expected = df_multi_both .groupby (['B' ,
625- pd .Grouper (key = 'inner' )]).mean ()
639+ pd .Grouper (key = 'inner' )]).mean ()
626640 assert_frame_equal (result , expected )
627641
628642 not_expected = df_multi_both .groupby (['B' ,
629643 pd .Grouper (level = 'inner' )
630644 ]).mean ()
631- assert not result .index .equals (not_expected .index )
645+ self . assertFalse ( result .index .equals (not_expected .index ) )
632646
633647 # Group MultiIndex by two keys (2)
634- result = df_multi_both .groupby (['inner' , 'B' ]).mean ()
648+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
649+ result = df_multi_both .groupby (['inner' , 'B' ]).mean ()
650+
635651 expected = df_multi_both .groupby ([pd .Grouper (key = 'inner' ),
636652 'B' ]).mean ()
637653 assert_frame_equal (result , expected )
638654
639655 not_expected = df_multi_both .groupby ([pd .Grouper (level = 'inner' ),
640656 'B' ]).mean ()
641- assert not result .index .equals (not_expected .index )
657+ self . assertFalse ( result .index .equals (not_expected .index ) )
642658
643659 # Group single Index by two keys (1)
644- result = df_single_both .groupby (['B' , 'inner' ]).mean ()
660+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
661+ result = df_single_both .groupby (['B' , 'inner' ]).mean ()
662+
645663 expected = df_single_both .groupby (['B' ,
646- pd .Grouper (key = 'inner' )]).mean ()
664+ pd .Grouper (key = 'inner' )]).mean ()
647665 assert_frame_equal (result , expected )
648666
649667 not_expected = df_single_both .groupby (['B' ,
650668 pd .Grouper (level = 'inner' )
651669 ]).mean ()
652- assert not result .index .equals (not_expected .index )
670+ self . assertFalse ( result .index .equals (not_expected .index ) )
653671
654672 # Group single Index by two keys (2)
655- result = df_single_both .groupby (['inner' , 'B' ]).mean ()
673+ with tm .assert_produces_warning (FutureWarning , check_stacklevel = False ):
674+ result = df_single_both .groupby (['inner' , 'B' ]).mean ()
675+
656676 expected = df_single_both .groupby ([pd .Grouper (key = 'inner' ),
657677 'B' ]).mean ()
658678 assert_frame_equal (result , expected )
659679
660680 not_expected = df_single_both .groupby ([pd .Grouper (level = 'inner' ),
661681 'B' ]).mean ()
662- assert not result .index .equals (not_expected .index )
682+ self . assertFalse ( result .index .equals (not_expected .index ) )
663683
664684 def test_grouper_getting_correct_binner (self ):
665685
0 commit comments