1
- import cython
2
- from cython import Py_ssize_t
3
-
4
- from cython cimport floating
1
+ cimport cython
2
+ from cython cimport (
3
+ Py_ssize_t,
4
+ floating,
5
+ )
5
6
from libc.stdlib cimport (
6
7
free,
7
8
malloc,
@@ -268,7 +269,6 @@ def group_cumsum(
268
269
out[i, j] = na_val
269
270
continue
270
271
271
-
272
272
if isna_entry:
273
273
out[i, j] = na_val
274
274
if not skipna:
@@ -1220,7 +1220,7 @@ def group_nth(
1220
1220
if nobs[lab, j] == rank:
1221
1221
resx[lab, j] = val
1222
1222
1223
- # TODO: de-dup this whoel block with group_last?
1223
+ # TODO: de-dup this whole block with group_last?
1224
1224
for i in range (ncounts):
1225
1225
for j in range (K):
1226
1226
if nobs[i, j] < min_count:
@@ -1232,6 +1232,9 @@ def group_nth(
1232
1232
# set a placeholder value in out[i, j].
1233
1233
if uses_mask:
1234
1234
result_mask[i, j] = True
1235
+ # set out[i, j] to 0 to be deterministic, as
1236
+ # it was initialized with np.empty. Also ensures
1237
+ # we can downcast out if appropriate.
1235
1238
out[i, j] = 0
1236
1239
elif numeric_object_t is float32_t or numeric_object_t is float64_t:
1237
1240
out[i, j] = NAN
@@ -1369,7 +1372,7 @@ cdef group_min_max(
1369
1372
"""
1370
1373
cdef:
1371
1374
Py_ssize_t i, j, N, K, lab, ngroups = len (counts)
1372
- numeric_t val, nan_val
1375
+ numeric_t val
1373
1376
ndarray[numeric_t, ndim= 2 ] group_min_or_max
1374
1377
int64_t[:, ::1 ] nobs
1375
1378
bint uses_mask = mask is not None
@@ -1386,20 +1389,6 @@ cdef group_min_max(
1386
1389
group_min_or_max = np.empty_like(out)
1387
1390
group_min_or_max[:] = _get_min_or_max(< numeric_t> 0 , compute_max, is_datetimelike)
1388
1391
1389
- # NB: We do not define nan_val because there is no such thing
1390
- # for uint64_t. We carefully avoid having to reference it in this
1391
- # case.
1392
- if numeric_t is int64_t:
1393
- nan_val = NPY_NAT
1394
- elif numeric_t is int32_t:
1395
- nan_val = util.INT32_MIN
1396
- elif numeric_t is int16_t:
1397
- nan_val = util.INT16_MIN
1398
- elif numeric_t is int8_t:
1399
- nan_val = util.INT8_MIN
1400
- elif numeric_t is float64_t or numeric_t is float32_t:
1401
- nan_val = NAN
1402
-
1403
1392
N, K = (< object > values).shape
1404
1393
1405
1394
with nogil:
@@ -1442,11 +1431,11 @@ cdef group_min_max(
1442
1431
# we can downcast out if appropriate.
1443
1432
out[i, j] = 0
1444
1433
elif numeric_t is float32_t or numeric_t is float64_t:
1445
- out[i, j] = nan_val
1434
+ out[i, j] = NAN
1446
1435
elif numeric_t is int64_t:
1447
1436
# Per above, this is a placeholder in
1448
1437
# non-is_datetimelike cases.
1449
- out[i, j] = nan_val
1438
+ out[i, j] = NPY_NAT
1450
1439
else :
1451
1440
# placeholder, see above
1452
1441
out[i, j] = 0
0 commit comments