Skip to content

Commit 82d4ec4

Browse files
committed
BUG: summing boolean DataFrame
1 parent 3750d44 commit 82d4ec4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pandas/core/frame.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,10 @@ def sum(self, axis=0, numeric_only=False):
20022002
y[-mask] = 0
20032003
the_sum = y.sum(axis)
20042004
the_count = mask.sum(axis)
2005-
the_sum[the_count == 0] = nan
2005+
2006+
ct_mask = the_count == 0
2007+
if ct_mask.any():
2008+
the_sum[ct_mask] = nan
20062009

20072010
return Series(the_sum, index=axis_labels)
20082011

pandas/tests/test_frame.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,6 +2079,12 @@ def test_sum_object(self):
20792079
deltas = frame * timedelta(1)
20802080
deltas.sum()
20812081

2082+
def test_sum_bool(self):
2083+
# ensure this works, bug report
2084+
bools = np.isnan(self.frame)
2085+
bools.sum(1)
2086+
bools.sum(0)
2087+
20822088
def test_product(self):
20832089
def f(x):
20842090
x = np.asarray(x)

0 commit comments

Comments
 (0)