@@ -286,6 +286,25 @@ def test_pivot_with_interval_index(self, interval_values, dropna):
286
286
expected = DataFrame ({"B" : 1 }, index = Index (interval_values .unique (), name = "A" ))
287
287
tm .assert_frame_equal (result , expected )
288
288
289
+ def test_pivot_with_interval_index_margins (self , dropna ):
290
+ # GH 25815
291
+ ordered_cat = pd .IntervalIndex .from_arrays (
292
+ [0 , 0 , 1 , 1 ], [1 , 1 , 2 , 2 ])
293
+ df = pd .DataFrame ({
294
+ 'A' : np .arange (4 , 0 , - 1 ),
295
+ 'B' : ['a' , 'b' , 'a' , 'b' ],
296
+ 'C' : pd .Categorical (ordered_cat ,
297
+ ordered = True ).sort_values (ascending = False )
298
+ })
299
+
300
+ pivot_tab = pd .pivot_table (data = df , index = 'C' , columns = 'B' , values = 'A' ,
301
+ aggfunc = 'sum' , margins = True )
302
+
303
+ result = pivot_tab ['All' ]
304
+ expected = pivot_tab .iloc [:, :- 1 ].sum (axis = 1 )
305
+ tm .assert_series_equal (result , expected , check_dtype = False ,
306
+ check_names = False )
307
+
289
308
def test_pass_array (self ):
290
309
result = self .data .pivot_table ("D" , index = self .data .A , columns = self .data .C )
291
310
expected = self .data .pivot_table ("D" , index = "A" , columns = "C" )
0 commit comments