flox implements all common reductions provided by numpy_groupies in Control this by passing the func kwarg:

  • "sum", "nansum"

  • "prod", "nanprod"

  • "count" - number of non-NaN elements by group

  • "mean", "nanmean"

  • "var", "nanvar"

  • "std", "nanstd"

  • "argmin"

  • "argmax"

  • "first", "nanfirst"

  • "last", "nanlast"

  • "median", "nanmedian"

  • "mode", "nanmode"

  • "quantile", "nanquantile"


We would like to add support for cumsum, cumprod (issue). Contributions are welcome!

Custom Aggregations

flox also allows you to specify a custom Aggregation (again inspired by dask.dataframe), though this might not be fully functional at the moment. See for examples.

See the “Custom Aggregations” user story for a more user-friendly example.

mean = Aggregation(
    # name used for dask tasks
    # operation to use for pure-numpy inputs
    # blockwise reduction
    chunk=("sum", "count"),
    # combine intermediate results: sum the sums, sum the counts
    combine=("sum", "sum"),
    # generate final result as sum / count
    finalize=lambda sum_, count: sum_ / count,
    # Used when "reindexing" at combine-time
    # Used when any member of `expected_groups` is not found