Parapply
A simple drop-in replacement for parallelized pandas apply() on large Series / DataFrames, using joblib. Works by dividing the Series / DataFrame into multiple chunks and running apply concurrently. As a rule of thumb, use parapply only if you have 10 million rows and above (see benchmark below).
Install by running pip install parapply. Requires joblib, numpy, and pandas (obviously!)
Simple Usage
Series: parapply(srs, fun) instead of srs.apply(fun)
DataFrames: parapply(df, fun, axis) instead of df.apply(fun, axis)
For more fine grain control:
+ n_jobs to decide number of concurrent jobs,
+ n_chunks for number of chunks to split the Series / DataFrame
Examples:
import pandas as pd
import numpy as np
from parapply import parapply
# Series example
np.random.seed(0)
srs = pd.Series(np.random.random(size=(5, )))
pd_apply_result = srs.apply(lambda x: x ** 2)
parapply_result = parapply(srs, lambda x: x ** 2)
print(pd_apply_result)
# 0 0.301196
# 1 0.511496
# 2 0.363324
# 3 0.296898
# 4 0.179483
# dtype: float64
print(parapply_result)
# 0 0.301196
# 1 0.511496
# 2 0.363324
# 3 0.296898
# 4 0.179483
# dtype: float64
# DataFrame example with axis = 1
np.random.seed(1)
df = pd.DataFrame(data={
'a': np.random.random(size=(5, )),
'b': np.random.random(size=(5, )),
'c': np.random.random(size=(5, )),
})
pd_apply_result = df.apply(sum, axis=1)
parapply_result = parapply(df, sum, axis=1)
print(pd_apply_result)
# 0 0.928555
# 1 1.591804
# 2 0.550127
# 3 1.577217
# 4 0.712960
# dtype: float64
print(parapply_result)
# 0 0.928555
# 1 1.591804
# 2 0.550127
# 3 1.577217
# 4 0.712960
# dtype: float64
Refer to docstrings for more information.
Quick and dirty benchmarks
Ran a quick and dirty benchmark to compare time taken to apply lambda x:x ** 2 to Series of varying length using pandas apply and parapply on multiple n_jobs settings:
This semilog plot above shows that significant runtime differences between pandas apply and parapply show up at 10 million data points and onwards.
Acknowledgements
Thanks to @aaronlhe for introducing me to the world of unit tests!
Metadata
Release files for parapply 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| parapply-0.0.2.tar.gz | 4.8 kB | Without provenance | Details for parapply-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| parapply-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for parapply-0.0.2-py3-none-any.whl |
Total release size: 11.6 kB
Release files / parapply-0.0.2.tar.gz
| Download URL | parapply-0.0.2.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
090dd8db2bd6817c8ddad717a95726199a48f33ba245ef10b69d86c6b5bb3c26
|
|
BLAKE2b-256 checksum How to use checksums |
57f913f826a1255476c4ad49098dfd2c8d194da7063d93dea799b15385fc2e12
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0.post20191030 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
|
Release files / parapply-0.0.2-py3-none-any.whl
| Download URL | parapply-0.0.2-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cb7680ce72f7a4d8acd0979cc4015ee1b7292ef86f3839816ec642c637dbec98
|
|
BLAKE2b-256 checksum How to use checksums |
e5a6499ac82a880b740145d200b98b4ff7ee74f51aafb55c712c4be9db581eb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0.post20191030 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
|
Security for parapply 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.