@@ -1714,3 +1714,35 @@ def test_groupby_multiindex_nat():
1714
1714
result = ser .groupby (level = 1 ).mean ()
1715
1715
expected = pd .Series ([3. , 2.5 ], index = ["a" , "b" ])
1716
1716
assert_series_equal (result , expected )
1717
+
1718
+
1719
+ def test_idxmin_idxmax_returns_int_types ():
1720
+ df = pd .DataFrame ({'name' : ['A' , 'A' , 'B' , 'B' ],
1721
+ 'c_int' : [1 , 2 , 3 , 4 ],
1722
+ 'c_float' : [4.02 , 3.03 , 2.04 , 1.05 ],
1723
+ 'c_date' : ['2019' , '2018' , '2016' , '2017' ]})
1724
+ df ['c_date' ] = pd .to_datetime (df ['c_date' ])
1725
+
1726
+ idxmins_computed = df .groupby ('name' ).idxmin ()
1727
+ idxmaxs_computed = df .groupby ('name' ).idxmax ()
1728
+
1729
+ for col in idxmaxs_computed :
1730
+ assert idxmins_computed [col ].dtype == np .int64
1731
+ assert idxmaxs_computed [col ].dtype == np .int64
1732
+
1733
+ idxmins_expected = pd .DataFrame ({'c_int' : [0 , 2 ],
1734
+ 'c_float' : [1 , 3 ],
1735
+ 'c_date' : [1 , 2 ]},
1736
+ index = ['A' , 'B' ])
1737
+
1738
+ idxmins_expected .index .name = "name"
1739
+
1740
+ idxmaxs_expected = pd .DataFrame ({'c_int' : [1 , 3 ],
1741
+ 'c_float' : [0 , 2 ],
1742
+ 'c_date' : [0 , 3 ]},
1743
+ index = ['A' , 'B' ])
1744
+
1745
+ idxmaxs_expected .index .name = "name"
1746
+
1747
+ assert_frame_equal (idxmins_expected , idxmins_computed )
1748
+ assert_frame_equal (idxmaxs_expected , idxmaxs_computed )
0 commit comments