Skip to content

Commit a2223db

Browse files
committed
Implemented skipna logic
1 parent ed65b30 commit a2223db

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
@@ -888,20 +888,23 @@ def group_any(ndarray[int64_t] out,
888888
cdef:
889889
Py_ssize_t i, N=len(labels)
890890
int64_t lab
891-
ndarray[int64_t] mask
891+
ndarray[int64_t] bool_mask
892+
ndarray[uint8_t] isna_mask
892893

893-
if values.dtype is np.object:
894-
mask = np.array(bool(x) for x in values).astype(np.int64)
894+
if values.dtype == 'object':
895+
bool_mask = np.array([bool(x) for x in values]).astype(np.int64)
896+
isna_mask = missing.isnaobj(values).astype(np.uint8)
895897
else:
896-
mask = values.astype(np.bool).astype(np.int64)
898+
bool_mask = values.astype(np.bool).astype(np.int64)
899+
isna_mask = np.isnan(values).astype(np.uint8)
897900

898901
with nogil:
899902
for i in range(N):
900903
lab = labels[i]
901904
if lab < 0:
902905
continue
903906

904-
if mask[i]:
907+
if bool_mask[i] and not (skipna and isna_mask[i]):
905908
out[lab] = 1
906909

907910

0 commit comments

Comments
 (0)