@@ -1180,17 +1180,18 @@ def test_margin_dropna(self):
11801180 df = pd .DataFrame ({'a' : [1 , 2 , 2 , 2 , 2 , np .nan ],
11811181 'b' : [3 , 3 , 4 , 4 , 4 , 4 ]})
11821182 actual = pd .crosstab (df .a , df .b , margins = True , dropna = False )
1183- expected = pd .DataFrame ([[1 , 0 , 1 ], [1 , 3 , 4 ], [2 , 4 , 6 ]])
1184- expected .index = Index ([1.0 , 2.0 , 'All' ], name = 'a' )
1183+ expected = pd .DataFrame ([[1 , 0 , 1 ], [1 , 3 , 4 ], [0 , 1 , 1 ], [ 2 , 4 , 6 ]])
1184+ expected .index = Index ([1.0 , 2.0 , np . nan , 'All' ], name = 'a' )
11851185 expected .columns = Index ([3 , 4 , 'All' ], name = 'b' )
11861186 tm .assert_frame_equal (actual , expected )
11871187
11881188 df = DataFrame ({'a' : [1 , np .nan , np .nan , np .nan , 2 , np .nan ],
11891189 'b' : [3 , np .nan , 4 , 4 , 4 , 4 ]})
11901190 actual = pd .crosstab (df .a , df .b , margins = True , dropna = False )
1191- expected = pd .DataFrame ([[1 , 0 , 1 ], [0 , 1 , 1 ], [1 , 4 , 6 ]])
1192- expected .index = Index ([1.0 , 2.0 , 'All' ], name = 'a' )
1193- expected .columns = Index ([3.0 , 4.0 , 'All' ], name = 'b' )
1191+ expected = pd .DataFrame ([[1 , 0 , 0 , 1 ], [0 , 1 , 0 , 1 ], [0 , 3 , 1 , 4 ],
1192+ [1 , 4 , 0 , 6 ]])
1193+ expected .index = Index ([1.0 , 2.0 , np .nan , 'All' ], name = 'a' )
1194+ expected .columns = Index ([3.0 , 4.0 , np .nan , 'All' ], name = 'b' )
11941195 tm .assert_frame_equal (actual , expected )
11951196
11961197 a = np .array (['foo' , 'foo' , 'foo' , 'bar' ,
@@ -1202,21 +1203,25 @@ def test_margin_dropna(self):
12021203
12031204 actual = pd .crosstab (a , [b , c ], rownames = ['a' ],
12041205 colnames = ['b' , 'c' ], margins = True , dropna = False )
1205- m = MultiIndex .from_arrays ([['one' , 'one' , 'two' , 'two' , 'All' ],
1206- ['dull' , 'shiny' , 'dull' , 'shiny' , '' ]],
1206+ m = MultiIndex .from_arrays ([[np .nan , np .nan , 'one' , 'one' , 'two' ,
1207+ 'two' , 'All' ],
1208+ ['dull' , 'shiny' , 'dull' , 'shiny' , 'dull' ,
1209+ 'shiny' , '' ]],
12071210 names = ['b' , 'c' ])
1208- expected = DataFrame ([[1 , 0 , 1 , 0 , 2 ], [2 , 0 , 1 , 1 , 5 ],
1209- [3 , 0 , 2 , 1 , 7 ]], columns = m )
1211+ expected = DataFrame ([[0 , 0 , 1 , 0 , 1 , 0 , 2 ], [0 , 1 , 2 , 0 , 1 , 1 , 5 ],
1212+ [0 , 1 , 3 , 0 , 2 , 1 , 7 ]], columns = m )
12101213 expected .index = Index (['bar' , 'foo' , 'All' ], name = 'a' )
12111214 tm .assert_frame_equal (actual , expected )
12121215
12131216 actual = pd .crosstab ([a , b ], c , rownames = ['a' , 'b' ],
12141217 colnames = ['c' ], margins = True , dropna = False )
1215- m = MultiIndex .from_arrays ([['bar' , 'bar' , 'foo' , 'foo' , 'All' ],
1216- ['one' , 'two' , 'one' , 'two' , '' ]],
1218+ m = MultiIndex .from_arrays ([['bar' , 'bar' , 'bar' , 'foo' , 'foo' ,
1219+ 'foo' , 'All' ],
1220+ [np .nan , 'one' , 'two' , np .nan , 'one' ,
1221+ 'two' , '' ]],
12171222 names = ['a' , 'b' ])
1218- expected = DataFrame ([[1 , 0 , 1 ], [1 , 0 , 1 ], [2 , 0 , 2 ], [1 , 1 , 2 ],
1219- [5 , 2 , 7 ]], index = m )
1223+ expected = DataFrame ([[0 , 0 , 0 ], [1 , 0 , 1 ], [1 , 0 , 1 ], [0 , 1 , 1 ],
1224+ [2 , 0 , 2 ], [ 1 , 1 , 2 ], [ 5 , 2 , 7 ]], index = m )
12201225 expected .columns = Index (['dull' , 'shiny' , 'All' ], name = 'c' )
12211226 tm .assert_frame_equal (actual , expected )
12221227
0 commit comments