Skip to content

Commit 0444066

Browse files
committed
Implemented skipna logic
1 parent cdb3f57 commit 0444066

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

pandas/_libs/groupby.pyx

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ from algos cimport (swap, TiebreakEnumType, TIEBREAK_AVERAGE, TIEBREAK_MIN,
2020
TIEBREAK_MAX, TIEBREAK_FIRST, TIEBREAK_DENSE)
2121
from algos import take_2d_axis1_float64_float64, groupsort_indexer, tiebreakers
2222

23+
import missing
24+
2325
cdef int64_t iNaT = get_nat()
2426

2527
cdef double NaN = <double> np.NaN

pandas/_libs/groupby_helper.pxi.in

+8-5
Original file line numberDiff line numberDiff line change
@@ -801,18 +801,21 @@ def group_any(ndarray[int64_t] out,
801801
cdef:
802802
Py_ssize_t i, N=len(labels)
803803
int64_t lab
804-
ndarray[int64_t] mask
804+
ndarray[int64_t] bool_mask
805+
ndarray[uint8_t] isna_mask
805806

806-
if values.dtype is np.object:
807-
mask = np.array(bool(x) for x in values).astype(np.int64)
807+
if values.dtype == 'object':
808+
bool_mask = np.array([bool(x) for x in values]).astype(np.int64)
809+
isna_mask = missing.isnaobj(values).astype(np.uint8)
808810
else:
809-
mask = values.astype(np.bool).astype(np.int64)
811+
bool_mask = values.astype(np.bool).astype(np.int64)
812+
isna_mask = np.isnan(values).astype(np.uint8)
810813

811814
with nogil:
812815
for i in range(N):
813816
lab = labels[i]
814817
if lab < 0:
815818
continue
816819

817-
if mask[i]:
820+
if bool_mask[i] and not (skipna and isna_mask[i]):
818821
out[lab] = 1

0 commit comments

Comments
 (0)