@@ -24,7 +24,7 @@ def _sum(group_idx, a, size, fill_value, dtype=None):
24
24
dtype = minimum_dtype_scalar (fill_value , dtype , a )
25
25
26
26
if np .ndim (a ) == 0 :
27
- ret = np .bincount (group_idx , minlength = size ).astype (dtype )
27
+ ret = np .bincount (group_idx , minlength = size ).astype (dtype , copy = False )
28
28
if a != 1 :
29
29
ret *= a
30
30
else :
@@ -33,7 +33,9 @@ def _sum(group_idx, a, size, fill_value, dtype=None):
33
33
ret .real = np .bincount (group_idx , weights = a .real , minlength = size )
34
34
ret .imag = np .bincount (group_idx , weights = a .imag , minlength = size )
35
35
else :
36
- ret = np .bincount (group_idx , weights = a , minlength = size ).astype (dtype )
36
+ ret = np .bincount (group_idx , weights = a , minlength = size ).astype (
37
+ dtype , copy = False
38
+ )
37
39
38
40
if fill_value != 0 :
39
41
_fill_untouched (group_idx , ret , fill_value )
@@ -146,19 +148,19 @@ def _mean(group_idx, a, size, fill_value, dtype=np.dtype(np.float64)):
146
148
sums .real = np .bincount (group_idx , weights = a .real , minlength = size )
147
149
sums .imag = np .bincount (group_idx , weights = a .imag , minlength = size )
148
150
else :
149
- sums = np .bincount (group_idx , weights = a , minlength = size ).astype (dtype )
151
+ sums = np .bincount (group_idx , weights = a , minlength = size ).astype (dtype , copy = False )
150
152
151
153
with np .errstate (divide = "ignore" , invalid = "ignore" ):
152
- ret = sums .astype (dtype ) / counts
154
+ ret = sums .astype (dtype , copy = False ) / counts
153
155
if not np .isnan (fill_value ):
154
156
ret [counts == 0 ] = fill_value
155
157
return ret
156
158
157
159
158
160
def _sum_of_squres (group_idx , a , size , fill_value , dtype = np .dtype (np .float64 )):
159
161
ret = np .bincount (group_idx , weights = a * a , minlength = size )
160
- counts = np .bincount (group_idx , minlength = size )
161
162
if fill_value != 0 :
163
+ counts = np .bincount (group_idx , minlength = size )
162
164
ret [counts == 0 ] = fill_value
163
165
return ret
164
166
@@ -171,7 +173,7 @@ def _var(
171
173
counts = np .bincount (group_idx , minlength = size )
172
174
sums = np .bincount (group_idx , weights = a , minlength = size )
173
175
with np .errstate (divide = "ignore" , invalid = "ignore" ):
174
- means = sums .astype (dtype ) / counts
176
+ means = sums .astype (dtype , copy = False ) / counts
175
177
counts = np .where (counts > ddof , counts - ddof , 0 )
176
178
ret = (
177
179
np .bincount (group_idx , (a - means [group_idx ]) ** 2 , minlength = size ) / counts
@@ -299,6 +301,7 @@ def _aggregate_base(
299
301
dtype = None ,
300
302
axis = None ,
301
303
_impl_dict = _impl_dict ,
304
+ is_pandas = False ,
302
305
** kwargs
303
306
):
304
307
iv = input_validation (group_idx , a , size = size , order = order , axis = axis , func = func )
@@ -324,7 +327,9 @@ def _aggregate_base(
324
327
kwargs ["_nansqueeze" ] = True
325
328
else :
326
329
good = ~ np .isnan (a )
327
- a = a [good ]
330
+ if "len" not in func or is_pandas :
331
+ # a is not needed for len, nanlen!
332
+ a = a [good ]
328
333
group_idx = group_idx [good ]
329
334
330
335
dtype = check_dtype (dtype , func , a , flat_size )
0 commit comments