Skip to content

Commit 9f2b006

Browse files
committed
Initial wiring and working func, save all NaNs
1 parent fc23a73 commit 9f2b006

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

pandas/_libs/groupby_helper.pxi.in

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -881,27 +881,22 @@ def group_cummax_{{name}}(ndarray[{{dest_type2}}, ndim=2] out,
881881

882882
@cython.boundscheck(False)
883883
@cython.wraparound(False)
884-
def group_any(ndarray[uint8_t, ndim=2] out,
885-
ndarray[int64_t] counts,
886-
ndarray[:, :] values,
884+
def group_any(ndarray[int64_t] out,
885+
ndarray[int64_t] mask,
887886
ndarray[int64_t] labels,
888887
bint skipna):
889888
cdef:
890-
Py_ssize_t i, N
891-
ndarray[uint8_t] mask
892-
893-
N, _ = (<object> labels).shape
894-
895-
out = np.zeros_like(out)
896-
mask = values[:, 0].astype(np.bool)
889+
Py_ssize_t i, N=len(labels)
890+
int64_t lab
897891

898-
for i in range(N):
899-
lab = labels[i]
900-
if lab < 0:
901-
continue
892+
with nogil:
893+
for i in range(N):
894+
lab = labels[i]
895+
if lab < 0:
896+
continue
902897

903-
if mask[lab]:
904-
out[lab, 0] = 1
898+
if mask[i]:
899+
out[lab] = 1
905900

906901

907902
@cython.boundscheck(False)

pandas/core/groupby.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,26 @@ class GroupBy(_GroupBy):
12191219
"""
12201220
_apply_whitelist = _common_apply_whitelist
12211221

1222+
@Substitution(name='groupby')
1223+
@Appender(_doc_template)
1224+
def any(self, skipna=True):
1225+
"""Returns True if any value in the group is truthful, else False"""
1226+
obj = self._obj_with_exclusions
1227+
1228+
labels, _, _ = self.grouper.group_info
1229+
1230+
output = collections.OrderedDict()
1231+
for name, obj in self._iterate_slices():
1232+
result = np.zeros(self.ngroups, dtype=np.int64)
1233+
if obj.dtype is np.object:
1234+
mask = np.array(bool(x) for x in obj.values)
1235+
else:
1236+
mask = obj.values.astype(np.bool)
1237+
libgroupby.group_any(result, mask.astype(np.int64), labels, skipna)
1238+
output[name] = result.astype(np.bool)
1239+
1240+
return self._wrap_aggregated_output(output)
1241+
12221242
@Substitution(name='groupby')
12231243
@Appender(_doc_template)
12241244
def count(self):

0 commit comments

Comments
 (0)