@@ -312,5 +312,50 @@ def group_fillna_indexer(ndarray[int64_t] out, ndarray[int64_t] labels,
312
312
filled_vals = 0
313
313
314
314
315
+ @ cython.boundscheck (False )
316
+ @ cython.wraparound (False )
317
+ def group_any (ndarray[int64_t] out ,
318
+ ndarray values ,
319
+ ndarray[int64_t] labels ,
320
+ bint skipna ):
321
+ """ Aggregated boolean values to show if any group element is truthful
322
+
323
+ Parameters
324
+ ----------
325
+ out : array of int64_t values which this method will write its results to
326
+ values : array of values to be truth-tested
327
+ labels : array containing unique label for each group, with its ordering
328
+ matching up to the corresponding record in `values`
329
+ skipna : boolean
330
+ Flag to ignore nan values during truth testing
331
+
332
+ Notes
333
+ -----
334
+ This method modifies the `out` parameter rather than returning an object.
335
+ The returned values will either be 0 or 1 (False or True, respectively).
336
+ """
337
+ cdef:
338
+ Py_ssize_t i, N= len (labels)
339
+ int64_t lab
340
+ ndarray[int64_t] bool_mask
341
+ ndarray[uint8_t] isna_mask
342
+
343
+ if values.dtype == ' object' :
344
+ bool_mask = np.array([bool (x) for x in values]).astype(np.int64)
345
+ isna_mask = missing.isnaobj(values).astype(np.uint8)
346
+ else :
347
+ bool_mask = values.astype(np.bool).astype(np.int64)
348
+ isna_mask = np.isnan(values).astype(np.uint8)
349
+
350
+ with nogil:
351
+ for i in range (N):
352
+ lab = labels[i]
353
+ if lab < 0 :
354
+ continue
355
+
356
+ if bool_mask[i] and not (skipna and isna_mask[i]):
357
+ out[lab] = 1
358
+
359
+
315
360
# generated from template
316
361
include " groupby_helper.pxi"
0 commit comments