Skip to content

Commit 8d75c55

Browse files
committed
fix dropna=false tests
1 parent 0252385 commit 8d75c55

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pandas/tools/tests/test_pivot.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,17 +1072,17 @@ def test_margin_dropna(self):
10721072
df = pd.DataFrame({'a': [1, 2, 2, 2, 2, np.nan],
10731073
'b': [3, 3, 4, 4, 4, 4]})
10741074
actual = pd.crosstab(df.a, df.b, margins=True, dropna=False)
1075-
expected = pd.DataFrame([[1, 0, 1], [1, 3, 4], [2, 4, 6]])
1076-
expected.index = Index([1.0, 2.0, 'All'], name='a')
1077-
expected.columns = Index([3, 4, 'All'], name='b')
1075+
expected = pd.DataFrame([[1, 0, 1], [1, 3, 4], [0, 1, 1], [2, 4, 6]])
1076+
expected.index = Index([1.0, 2.0, np.nan, 'All'], name='a')
1077+
expected.columns = Index([3.0, 4.0, 'All'], name='b')
10781078
tm.assert_frame_equal(actual, expected)
10791079

10801080
df = DataFrame({'a': [1, np.nan, np.nan, np.nan, 2, np.nan],
10811081
'b': [3, np.nan, 4, 4, 4, 4]})
10821082
actual = pd.crosstab(df.a, df.b, margins=True, dropna=False)
1083-
expected = pd.DataFrame([[1, 0, 1], [0, 1, 1], [1, 4, 6]])
1084-
expected.index = Index([1.0, 2.0, 'All'], name='a')
1085-
expected.columns = Index([3.0, 4.0, 'All'], name='b')
1083+
expected = pd.DataFrame([[1, 0, 0, 1], [0, 1, 0, 1], [0, 3, 1, 4], [1, 4, 1, 6]])
1084+
expected.index = Index([1.0, 2.0, np.nan, 'All'], name='a')
1085+
expected.columns = Index([3.0, 4.0, np.nan, 'All'], name='b')
10861086
tm.assert_frame_equal(actual, expected)
10871087

10881088
a = np.array(['foo', 'foo', 'foo', 'bar',
@@ -1094,20 +1094,20 @@ def test_margin_dropna(self):
10941094

10951095
actual = pd.crosstab(a, [b, c], rownames=['a'],
10961096
colnames=['b', 'c'], margins=True, dropna=False)
1097-
m = MultiIndex.from_arrays([['one', 'one', 'two', 'two', 'All'],
1098-
['dull', 'shiny', 'dull', 'shiny', '']],
1097+
m = MultiIndex.from_arrays([[np.nan, np.nan, 'one', 'one', 'two', 'two', 'All'],
1098+
['dull', 'shiny', 'dull', 'shiny', 'dull', 'shiny', '']],
10991099
names=['b', 'c'])
1100-
expected = DataFrame([[1, 0, 1, 0, 2], [2, 0, 1, 1, 5],
1101-
[3, 0, 2, 1, 7]], columns=m)
1100+
expected = DataFrame([[0, 0, 1, 0, 1, 0, 2], [0, 1, 2, 0, 1, 1, 5],
1101+
[0, 1, 3, 0, 2, 1, 7]], columns=m)
11021102
expected.index = Index(['bar', 'foo', 'All'], name='a')
11031103
tm.assert_frame_equal(actual, expected)
11041104

11051105
actual = pd.crosstab([a, b], c, rownames=['a', 'b'],
11061106
colnames=['c'], margins=True, dropna=False)
1107-
m = MultiIndex.from_arrays([['bar', 'bar', 'foo', 'foo', 'All'],
1108-
['one', 'two', 'one', 'two', '']],
1107+
m = MultiIndex.from_arrays([['bar', 'bar', 'bar', 'foo', 'foo', 'foo', 'All'],
1108+
[np.nan, 'one', 'two', np.nan, 'one', 'two', '']],
11091109
names=['a', 'b'])
1110-
expected = DataFrame([[1, 0, 1], [1, 0, 1], [2, 0, 2], [1, 1, 2],
1110+
expected = DataFrame([[0, 0, 0], [1, 0, 1], [1, 0, 1], [0, 1, 1], [2, 0, 2], [1, 1, 2],
11111111
[5, 2, 7]], index=m)
11121112
expected.columns = Index(['dull', 'shiny', 'All'], name='c')
11131113
tm.assert_frame_equal(actual, expected)

0 commit comments

Comments
 (0)