https://github.com/numbagg/numbagg
Fast N-dimensional aggregation functions with Numba
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.5%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Fast N-dimensional aggregation functions with Numba
Basic Info
Statistics
- Stars: 227
- Watchers: 5
- Forks: 18
- Open Issues: 12
- Releases: 29
Topics
Metadata Files
README.md
Numbagg: Fast N-dimensional aggregation functions with Numba
Fast, flexible N-dimensional array functions written with Numba and NumPy's generalized ufuncs.
Why use numbagg?
Performance
- Outperforms pandas
- On a single core, 2-10x faster for moving window functions, 1-2x faster for aggregation and grouping functions
- When parallelizing with multiple cores, 4-30x faster
- Outperforms bottleneck on multiple cores
- On a single core, matches bottleneck
- When parallelizing with multiple cores, 3-7x faster
- Outperforms numpy on multiple cores
- On a single core, matches numpy
- When parallelizing with multiple cores, 5-15x faster
- ...though numbagg's functions are JIT compiled, so the first run is much slower
Versatility
- More functions (though bottleneck has some functions we don't have, and pandas' functions have many more parameters)
- Functions work for >3 dimensions with flexible axis handling (see Axis Parameter Behavior below)
- Written in numba — way less code, simple to inspect, simple to improve
Functions & benchmarks
Summary benchmark
Two benchmarks summarize numbagg's performance — the first with a 1D array of 10M elements without parallelization, and a second with a 2D array of 100x10K elements with parallelization[^6]. Numbagg's relative performance is much higher where parallelization is possible. A wider range of arrays is listed in the full set of benchmarks below.
The values in the table are numbagg's performance as a multiple of other libraries for a given shaped array calculated over the final axis. (so 1.00x means numbagg is equal, higher means numbagg is faster.)
| func | 1D
pandas | 1D
bottleneck | 1D
numpy | 2D
pandas | 2D
bottleneck | 2D
numpy |
| :------------------------ | -----------: | ---------------: | ----------: | -----------: | ---------------: | ----------: |
| bfill | 1.06x | 1.13x | n/a | 11.11x | 5.04x | n/a |
| ffill | 1.12x | 0.99x | n/a | 11.50x | 4.25x | n/a |
| group_nanall | 1.38x | n/a | n/a | 7.77x | n/a | n/a |
| group_nanany | 1.12x | n/a | n/a | 6.21x | n/a | n/a |
| group_nanargmax | 1.16x | n/a | n/a | 6.81x | n/a | n/a |
| group_nanargmin | 1.17x | n/a | n/a | 6.48x | n/a | n/a |
| group_nancount | 1.05x | n/a | n/a | 4.94x | n/a | n/a |
| group_nanfirst | 1.52x | n/a | n/a | 11.13x | n/a | n/a |
| group_nanlast | 1.12x | n/a | n/a | 5.56x | n/a | n/a |
| group_nanmax | 1.13x | n/a | n/a | 5.13x | n/a | n/a |
| group_nanmean | 1.14x | n/a | n/a | 5.61x | n/a | n/a |
| group_nanmin | 1.12x | n/a | n/a | 5.75x | n/a | n/a |
| group_nanprod | 1.15x | n/a | n/a | 5.25x | n/a | n/a |
| group_nanstd | 1.14x | n/a | n/a | 5.41x | n/a | n/a |
| group_nansum_of_squares | 1.33x | n/a | n/a | 8.00x | n/a | n/a |
| group_nansum | 1.18x | n/a | n/a | 5.63x | n/a | n/a |
| group_nanvar | 1.13x | n/a | n/a | 4.88x | n/a | n/a |
| move_corr | 16.42x | n/a | n/a | 115.76x | n/a | n/a |
| move_cov | 12.30x | n/a | n/a | 86.56x | n/a | n/a |
| move_exp_nancorr | 6.65x | n/a | n/a | 46.98x | n/a | n/a |
| move_exp_nancount | 1.88x | n/a | n/a | 9.95x | n/a | n/a |
| move_exp_nancov | 6.53x | n/a | n/a | 43.63x | n/a | n/a |
| move_exp_nanmean | 1.61x | n/a | n/a | 10.65x | n/a | n/a |
| move_exp_nanstd | 1.76x | n/a | n/a | 12.40x | n/a | n/a |
| move_exp_nansum | 1.09x | n/a | n/a | 9.01x | n/a | n/a |
| move_exp_nanvar | 1.77x | n/a | n/a | 11.41x | n/a | n/a |
| move_mean | 6.03x | 1.34x | n/a | 26.60x | 6.25x | n/a |
| move_std | 4.76x | 0.89x | n/a | 29.09x | 6.24x | n/a |
| move_sum | 5.16x | 1.13x | n/a | 24.02x | 6.10x | n/a |
| move_var | 5.45x | 1.05x | n/a | 29.54x | 6.05x | n/a |
| nanargmax[^5] | 2.40x | 0.53x | n/a | 2.32x | 0.93x | n/a |
| nanargmin[^5] | 2.35x | 0.50x | n/a | 2.53x | 1.00x | n/a |
| nancount | 2.01x | n/a | 1.59x | 12.26x | n/a | 3.96x |
| nanmax[^5] | 3.15x | 0.50x | 0.09x | 3.59x | 3.24x | 0.09x |
| nanmean | 3.00x | 1.01x | 3.82x | 18.98x | 5.04x | 19.33x |
| nanmin[^5] | 3.07x | 0.50x | 0.09x | 3.39x | 3.03x | 0.09x |
| nanquantile | 0.69x | n/a | 0.53x | 4.94x | n/a | 4.33x |
| nanstd | 1.63x | 1.61x | 3.39x | 12.39x | 10.18x | 22.03x |
| nansum | 2.48x | 0.94x | 3.31x | 20.47x | 4.65x | 17.90x |
| nanvar | 1.61x | 1.65x | 3.40x | 12.62x | 10.49x | 22.13x |
Full benchmarks
[^1][^2][^3][^4][^5][^6]
[^1]:
Benchmarks were run on a Mac M3 Max laptop in September 2024 on numbagg's HEAD,
pandas 2.2.2, bottleneck 1.4.0 numpy 2.0.1, with python
numbagg/test/run_benchmarks.py -- --benchmark-max-time=10. They run in CI,
though GHA's low CPU count means we don't see the full benefits of
parallelization.
[^2]: While we separate the setup and the running of the functions, pandas still needs to do some work to create its result dataframe, and numbagg does some checks in python which bottleneck does in C or doesn't do. So use benchmarks on larger arrays for our summary so we can focus on the computational speed, which doesn't asymptote away. Any contributions to improve the benchmarks are welcome.
[^3]:
In some instances, a library won't have the exact function — for example,
pandas doesn't have an equivalent move_exp_nancount function, so we use
its sum function on an array of 1s. Similarly for
group_nansum_of_squares, we use two separate operations.
[^4]:
anynan & allnan are also functions in numbagg, but not listed here as they
require a different benchmark setup.
[^5]: This function is not currently parallelized, so exhibits worse performance on parallelizable arrays.
[^6]: Matrix functions (correlation/covariance matrices) use different array shapes in the summary benchmark: their largest 2D shape appears in the 1D column and their largest 3D shape appears in the 2D column to demonstrate parallelization across multiple independent matrices.
Axis parameter behavior
The axis parameter in numbagg has three different behaviors depending on the function type:
Aggregation functions
Includes: nanmean, nansum, nanstd, nanvar, nanmin, nanmax, nancount, nanargmin, nanargmax, nanquantile, allnan, anynan
- Specify dimensions to reduce/aggregate over
- Support multiple axes, e.g.
axis=(0, 1) - Remove the specified dimensions from output shape
```python
Example with 3D array
arr = np.random.rand(4, 3, 5) result = nb.nanmean(arr, axis=(0, 2)) # Reduces over dimensions 0 and 2
result.shape is (3,)
```
Moving window functions
Includes: move_mean, move_sum, move_std, move_var, move_corr, move_cov, and exponential variants like move_exp_nanmean
- Specify the dimension along which the window moves
- Single axis only
- Preserve input shape
```python
Moving average along axis 1
arr = np.random.rand(4, 3, 5) result = nb.move_mean(arr, window=2, axis=1)
result.shape is (4, 3, 5) - same as input
```
Grouped functions
Includes: group_nanmean, group_nansum, group_nanstd, group_nanvar, group_nanmin, group_nanmax, and others
- Specify dimension along which groups are defined
- Single axis only
- Group consecutive identical labels along the axis
```python
Group operations along axis 0
arr = np.random.rand(4, 3, 5) labels = np.array([0, 0, 1, 1]) # Groups for axis 0 result = nb.group_nanmean(arr, labels, axis=0)
result.shape is (2, 3, 5) - 2 groups along axis 0
```
Aggregation functions are compatible with NumPy's axis parameter behavior, while moving window and grouped functions provide functionality not available in NumPy.
Matrix functions
Includes: nancorrmatrix, nancovmatrix (static), and move_corrmatrix, move_covmatrix, move_exp_nancorrmatrix, move_exp_nancovmatrix (moving)
Matrix functions use different dimension conventions:
- Static matrix functions (
nancorrmatrix,nancovmatrix): expect(..., vars, obs)→(..., vars, vars) - Moving matrix functions (
move_corrmatrix,move_covmatrix,move_exp_nancorrmatrix,move_exp_nancovmatrix): expect(..., obs, vars)→(..., obs, vars, vars)
The different conventions follow a simple principle: dimensions should only be added or removed at the end of the array shape. Static functions both remove (the obs dimension) and add (a second vars dimension), so they need obs at the end. Moving functions only add (a second vars dimension), so they can keep the natural time-series ordering with obs before vars.
Example implementation
Numbagg makes it easy to write, in pure Python/NumPy, flexible aggregation functions accelerated by Numba. All the hard work is done by Numba's JIT compiler and NumPy's gufunc machinery (as wrapped by Numba).
For example, here is how we wrote nansum:
```python import numpy as np from numbagg.decorators import ndreduce
@ndreduce.wrap() def nansum(a): asum = 0.0 for ai in a.flat: if not np.isnan(ai): asum += ai return asum ```
Implementation details
Numbagg includes somewhat awkward workarounds for features missing from NumPy/Numba:
- It implements its own cache for functions wrapped by Numba's
guvectorize, because that decorator is rather slow. - It does its own handling of array
transposes
to handle the
axisargument in reduction functions. - It rewrites plain functions into gufuncs, to allow writing a traditional function while retaining the multidimensional advantages of gufuncs.
Already some of the ideas here have flowed upstream to numba (for example, an axis parameter), and we hope that others will follow.
License
3-clause BSD. Includes portions of Bottleneck, which is distributed under a Simplified BSD license.
Owner
- Name: numbagg
- Login: numbagg
- Kind: organization
- Repositories: 1
- Profile: https://github.com/numbagg
GitHub Events
Total
- Create event: 36
- Release event: 1
- Issues event: 9
- Watch event: 18
- Delete event: 40
- Issue comment event: 29
- Push event: 71
- Pull request review event: 17
- Pull request review comment event: 17
- Pull request event: 122
- Fork event: 4
Last Year
- Create event: 36
- Release event: 1
- Issues event: 9
- Watch event: 18
- Delete event: 40
- Issue comment event: 29
- Push event: 71
- Pull request review event: 17
- Pull request review comment event: 17
- Pull request event: 122
- Fork event: 4
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Maximilian Roos | 5****y | 191 |
| pre-commit-ci[bot] | 6****] | 83 |
| Stephan Hoyer | s****r@c****m | 48 |
| dependabot[bot] | 4****] | 22 |
| Mathias Hauser | m****e | 3 |
| Deepak Cherian | d****n | 2 |
| Maximilian Roos | 5****n | 1 |
| Francesco Zanetta | 6****e | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 35
- Total pull requests: 421
- Average time to close issues: 11 months
- Average time to close pull requests: 14 days
- Total issue authors: 13
- Total pull request authors: 9
- Average comments per issue: 3.51
- Average comments per pull request: 0.27
- Merged pull requests: 355
- Bot issues: 0
- Bot pull requests: 184
Past Year
- Issues: 7
- Pull requests: 121
- Average time to close issues: 3 months
- Average time to close pull requests: 2 days
- Issue authors: 7
- Pull request authors: 5
- Average comments per issue: 1.57
- Average comments per pull request: 0.16
- Merged pull requests: 94
- Bot issues: 0
- Bot pull requests: 68
Top Authors
Issue Authors
- max-sixty (12)
- dcherian (11)
- jennolsen84 (2)
- josephnowak (1)
- flying-sheep (1)
- OutSquareCapital (1)
- jsignell (1)
- 0x0L (1)
- frazane (1)
- shoyer (1)
- maawoo (1)
- rabernat (1)
- thomsonc4 (1)
Pull Request Authors
- max-sixty (214)
- pre-commit-ci[bot] (139)
- dependabot[bot] (45)
- shoyer (8)
- mathause (6)
- dcherian (5)
- frazane (2)
- jsignell (1)
- OutSquareCapital (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 3
-
Total downloads:
- pypi 93,558 last-month
-
Total dependent packages: 7
(may contain duplicates) -
Total dependent repositories: 62
(may contain duplicates) - Total versions: 30
- Total maintainers: 2
pypi.org: numbagg
Fast N-dimensional aggregation functions with Numba
- Documentation: https://numbagg.readthedocs.io/
- License: License ======= Numbagg is distributed under a BSD 3-clause license. It includes portions of Bottleneck, which is distributed under a Simplified BSD license. Numbagg license =============== BSD 3-Clause License Copyright (c) 2008-2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team Copyright (c) 2014-2018, Stephan Hoyer and Numbagg contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Bottleneck license ================== Copyright (c) 2010-2014 Berkeley Analytics, LLC. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
Latest release: 0.9.2
published 6 months ago
Rankings
Maintainers (2)
spack.io: py-numbagg
N-D labeled arrays and datasets in Python
- Homepage: https://github.com/numbagg/numbagg
- License: []
-
Latest release: 0.9.0
published 7 months ago
Rankings
conda-forge.org: numbagg
- Homepage: https://github.com/numbagg/numbagg
- License: BSD-3-Clause
-
Latest release: 0.2.1
published over 3 years ago
Rankings
Dependencies
- actions/checkout v3 composite
- actions/download-artifact v3 composite
- actions/setup-python v4 composite
- actions/upload-artifact v3 composite
- pypa/gh-action-pypi-publish v1.6.4 composite
- actions/cache v3 composite
- actions/checkout v3 composite
- actions/setup-python v4 composite
- conda-incubator/setup-miniconda v2 composite
- pre-commit/action v3.0.0 composite