Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -688,50 +688,6 @@ def generate_bins_dt64(ndarray[int64_t] values, const int64_t[:] binner,
return bins


@cython.boundscheck(False)
@cython.wraparound(False)
def row_bool_subset(const float64_t[:, :] values,
ndarray[uint8_t, cast=True] mask):
cdef:
Py_ssize_t i, j, n, k, pos = 0
ndarray[float64_t, ndim=2] out

n, k = (<object>values).shape
assert (n == len(mask))

out = np.empty((mask.sum(), k), dtype=np.float64)

for i in range(n):
if mask[i]:
for j in range(k):
out[pos, j] = values[i, j]
pos += 1

return out


@cython.boundscheck(False)
@cython.wraparound(False)
def row_bool_subset_object(ndarray[object, ndim=2] values,
ndarray[uint8_t, cast=True] mask):
cdef:
Py_ssize_t i, j, n, k, pos = 0
ndarray[object, ndim=2] out

n, k = (<object>values).shape
assert (n == len(mask))

out = np.empty((mask.sum(), k), dtype=object)

for i in range(n):
if mask[i]:
for j in range(k):
out[pos, j] = values[i, j]
pos += 1

return out


@cython.boundscheck(False)
@cython.wraparound(False)
def get_level_sorter(const int64_t[:] label,
Expand Down
12 changes: 2 additions & 10 deletions pandas/core/groupby/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
ensure_float64,
ensure_int64,
ensure_int_or_float,
ensure_object,
ensure_platform_int,
is_bool_dtype,
is_categorical_dtype,
Expand Down Expand Up @@ -567,15 +566,8 @@ def _cython_operation(self, kind, values, how, axis, min_count=-1, **kwargs):
result[mask] = np.nan

if kind == "aggregate" and self._filter_empty_groups and not counts.all():
if result.ndim == 2:
try:
result = lib.row_bool_subset(result, (counts > 0).view(np.uint8))
except ValueError:
result = lib.row_bool_subset_object(
ensure_object(result), (counts > 0).view(np.uint8)
)
else:
result = result[counts > 0]
assert result.ndim != 2
result = result[counts > 0]

if vdim == 1 and arity == 1:
result = result[:, 0]
Expand Down