@@ -448,31 +448,35 @@ def group_quantile(ndarray[float64_t] out,
448
448
grp_sz = counts[i]
449
449
non_na_sz = non_na_counts[i]
450
450
451
- # Calculate where to retrieve the desired value
452
- # Casting to int will intentionaly truncate result
453
- idx = grp_start + < int64_t> (q * < float64_t> (non_na_sz - 1 ))
454
-
455
- val = values[sort_arr[idx]]
456
- # If requested quantile falls evenly on a particular index
457
- # then write that index's value out. Otherwise interpolate
458
- q_idx = q * (non_na_sz - 1 )
459
- frac = q_idx % 1
460
-
461
- if frac == 0.0 or interp == INTERPOLATION_LOWER:
462
- out[i] = val
451
+ # If we have a group of all NA data we need to bail out
452
+ if non_na_sz == 0 :
453
+ out[i] = NaN
463
454
else :
464
- next_val = values[sort_arr[idx + 1 ]]
465
- if interp == INTERPOLATION_LINEAR:
466
- out[i] = val + (next_val - val) * frac
467
- elif interp == INTERPOLATION_HIGHER:
468
- out[i] = next_val
469
- elif interp == INTERPOLATION_MIDPOINT:
470
- out[i] = (val + next_val) / 2.0
471
- elif interp == INTERPOLATION_NEAREST:
472
- if frac > .5 or (frac == .5 and q > .5 ): # Always safe?
455
+ # Calculate where to retrieve the desired value
456
+ # Casting to int will intentionaly truncate result
457
+ idx = grp_start + < int64_t> (q * < float64_t> (non_na_sz - 1 ))
458
+
459
+ val = values[sort_arr[idx]]
460
+ # If requested quantile falls evenly on a particular index
461
+ # then write that index's value out. Otherwise interpolate
462
+ q_idx = q * (non_na_sz - 1 )
463
+ frac = q_idx % 1
464
+
465
+ if frac == 0.0 or interp == INTERPOLATION_LOWER:
466
+ out[i] = val
467
+ else :
468
+ next_val = values[sort_arr[idx + 1 ]]
469
+ if interp == INTERPOLATION_LINEAR:
470
+ out[i] = val + (next_val - val) * frac
471
+ elif interp == INTERPOLATION_HIGHER:
473
472
out[i] = next_val
474
- else :
475
- out[i] = val
473
+ elif interp == INTERPOLATION_MIDPOINT:
474
+ out[i] = (val + next_val) / 2.0
475
+ elif interp == INTERPOLATION_NEAREST:
476
+ if frac > .5 or (frac == .5 and q > .5 ): # Always safe?
477
+ out[i] = next_val
478
+ else :
479
+ out[i] = val
476
480
477
481
# Increment the index reference in sorted_arr for the next group
478
482
grp_start += grp_sz
0 commit comments