diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 27ee685acfde7..e8a1e8173e463 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -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 = (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 = (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, diff --git a/pandas/core/groupby/ops.py b/pandas/core/groupby/ops.py index e341a66bb7459..cc8aec4cc243b 100644 --- a/pandas/core/groupby/ops.py +++ b/pandas/core/groupby/ops.py @@ -20,7 +20,6 @@ ensure_float64, ensure_int64, ensure_int_or_float, - ensure_object, ensure_platform_int, is_bool_dtype, is_categorical_dtype, @@ -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]