Skip to content

Commit a6ef733

Browse files
committed
Count only masked (non-na) values.
1 parent 7d2fa42 commit a6ef733

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pandas/_libs/lib.pyx

+4-2
Original file line numberDiff line numberDiff line change
@@ -793,14 +793,16 @@ def count_level_2d(ndarray[uint8_t, ndim=2, cast=True] mask,
793793
with nogil:
794794
for i in range(n):
795795
for j in range(k):
796-
counts[labels[i], j] += mask[i, j]
796+
if mask[i, j]:
797+
counts[labels[i], j] += 1
797798

798799
else: # axis == 1
799800
counts = np.zeros((n, max_bin), dtype='i8')
800801
with nogil:
801802
for i in range(n):
802803
for j in range(k):
803-
counts[i, labels[j]] += mask[i, j]
804+
if mask[i, j]:
805+
counts[i, labels[j]] += 1
804806

805807
return counts
806808

0 commit comments

Comments
 (0)