Skip to content

Commit 16ad9a2

Browse files
committed
Optimize len, nanlen
1 parent d9355bd commit 16ad9a2

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

numpy_groupies/aggregate_numpy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ def _aggregate_base(
301301
dtype=None,
302302
axis=None,
303303
_impl_dict=_impl_dict,
304+
is_pandas=False,
304305
**kwargs
305306
):
306307
iv = input_validation(group_idx, a, size=size, order=order, axis=axis, func=func)
@@ -326,7 +327,9 @@ def _aggregate_base(
326327
kwargs["_nansqueeze"] = True
327328
else:
328329
good = ~np.isnan(a)
329-
a = a[good]
330+
if "len" not in func or is_pandas:
331+
# a is not needed for len, nanlen!
332+
a = a[good]
330333
group_idx = group_idx[good]
331334

332335
dtype = check_dtype(dtype, func, a, flat_size)

numpy_groupies/aggregate_pandas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def aggregate(
6969
func=func,
7070
axis=axis,
7171
_impl_dict=_impl_dict,
72+
is_pandas=True,
7273
**kwargs
7374
)
7475

0 commit comments

Comments
 (0)