Skip to content

Commit 35446fd

Browse files
committed
Moved group_any from template to .pyx
1 parent 9229f71 commit 35446fd

File tree

2 files changed

+45
-44
lines changed

2 files changed

+45
-44
lines changed

pandas/_libs/groupby.pyx

+45
Original file line numberDiff line numberDiff line change
@@ -312,5 +312,50 @@ def group_fillna_indexer(ndarray[int64_t] out, ndarray[int64_t] labels,
312312
filled_vals = 0
313313

314314

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+
315360
# generated from template
316361
include "groupby_helper.pxi"

pandas/_libs/groupby_helper.pxi.in

-44
Original file line numberDiff line numberDiff line change
@@ -791,47 +791,3 @@ def group_cummax_{{name}}(ndarray[{{dest_type2}}, ndim=2] out,
791791
out[i, j] = mval
792792

793793
{{endfor}}
794-
795-
@cython.boundscheck(False)
796-
@cython.wraparound(False)
797-
def group_any(ndarray[int64_t] out,
798-
ndarray values,
799-
ndarray[int64_t] labels,
800-
bint skipna):
801-
"""Aggregated boolean values to show if any group element is truthful
802-
803-
Parameters
804-
----------
805-
out : array of int64_t values which this method will write its results to
806-
values : array of values to be truth-tested
807-
labels : array containing unique label for each group, with its ordering
808-
matching up to the corresponding record in `values`
809-
skipna : boolean
810-
Flag to ignore nan values during truth testing
811-
812-
Notes
813-
-----
814-
This method modifies the `out` parameter rather than returning an object.
815-
The returned values will either be 0 or 1 (False or True, respectively).
816-
"""
817-
cdef:
818-
Py_ssize_t i, N=len(labels)
819-
int64_t lab
820-
ndarray[int64_t] bool_mask
821-
ndarray[uint8_t] isna_mask
822-
823-
if values.dtype == 'object':
824-
bool_mask = np.array([bool(x) for x in values]).astype(np.int64)
825-
isna_mask = missing.isnaobj(values).astype(np.uint8)
826-
else:
827-
bool_mask = values.astype(np.bool).astype(np.int64)
828-
isna_mask = np.isnan(values).astype(np.uint8)
829-
830-
with nogil:
831-
for i in range(N):
832-
lab = labels[i]
833-
if lab < 0:
834-
continue
835-
836-
if bool_mask[i] and not (skipna and isna_mask[i]):
837-
out[lab] = 1

0 commit comments

Comments
 (0)