BUG/PERF: sparse min/max don't densify by mzeitlin11 · Pull Request #43527 · pandas-dev/pandas (original) (raw)

This now follows the structure of other SparseArray reductions like sum more closely, though there is some added complexity here to avoid taking the min/max of an empty array, which would raise when we want to return the corresponding missing value instead.

Benchmarks:

       before           after         ratio
     [5deec13d]       [f3eea313]
     <master>         <perf_sparse_min_max>
-      4.05±0.3ms       11.6±0.3μs     0.00  sparse.MinMax.time_min_max('max', 0.0)
-      4.49±0.4ms       11.6±0.2μs     0.00  sparse.MinMax.time_min_max('min', 0.0)
-      4.62±0.7ms       10.6±0.2μs     0.00  sparse.MinMax.time_min_max('max', nan)
-      5.37±0.7ms       10.3±0.3μs     0.00  sparse.MinMax.time_min_max('min', nan)