Skip to main content

mapply

build codecov pypi Version python downloads

mapply provides a sensible multi-core apply function for Pandas.

mapply vs. pandarallel vs. swifter

Where pandarallel relies on in-house multiprocessing and progressbars, and hard-codes 1 chunk per worker (which will cause idle CPUs when one chunk happens to be more expensive than the others), swifter relies on the heavy dask framework for multiprocessing (converting to Dask DataFrames and back). In an attempt to find the golden mean, mapply is highly customizable and remains lightweight, using tqdm for progressbars and leveraging the powerful pathos framework, which shadows Python's built-in multiprocessing module using dill for universal pickling. Chunks of work are assigned to worker processes "just in time" from a shared queue, allowing irregular workloads to finish faster.

mapply vs. Pandas' numba engine

Pandas v1.3 added built-in support for running Numba compatible code in parallel with very low overhead (see Pandas' enhancing performance article). In contrast to mapply, which uses fork or spawn to perform multiprocessing, Numba can only automatically parallelize a subset of operations (see Numba's automatic parallelization article).

Installation

This pure-Python, OS independent package is available on PyPI:

$ pip install mapply

Usage

readthedocs

For documentation, see mapply.readthedocs.io.

import pandas as pd
import mapply

mapply.init(
    n_workers=-1,
    chunk_size=100,
    max_chunks_per_worker=8,
    progressbar=False,
)

df = pd.DataFrame({"A": list(range(100))})

# avoid unnecessary multiprocessing:
# due to chunk_size=100, this will act as regular apply.
# set chunk_size=1 to skip this check and let max_chunks_per_worker decide.
df["squared"] = df.A.mapply(lambda x: x**2)

Development

gitmoji pre-commit ruff

Run make help for options like installing for development, linting, testing, and building docs.


BSD 3-Clause License

Copyright (c) 2024, ddelange, ddelange@delange.dev

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. 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.

  3. 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.

SPDX-License-Identifier: BSD-3-Clause

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mapply-0.1.30.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mapply-0.1.30-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file mapply-0.1.30.tar.gz.

File metadata

  • Download URL: mapply-0.1.30.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for mapply-0.1.30.tar.gz
Algorithm Hash digest
SHA256 1d46305a99b6e5ab0636f5d981b73485e66e46d69248349cfd16d63ecc3b5adf
MD5 8ee1f7d8b40c1daf7002d18d19f2188a
BLAKE2b-256 420e62700825c81787d9dba50f61f09f444277d595757f451cfe9bea1630c85f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mapply-0.1.30.tar.gz:

Publisher: CD.yml on ddelange/mapply

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mapply-0.1.30-py3-none-any.whl.

File metadata

  • Download URL: mapply-0.1.30-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for mapply-0.1.30-py3-none-any.whl
Algorithm Hash digest
SHA256 fd5d768a338ed17f63295dafa02e05303d6b05a270dc7f39208efa7c141a28dd
MD5 dbc90641917854bc4eefe39d6d6400b3
BLAKE2b-256 ebb5104e8f6d1db2330a1b2e547505782c7ff32839b339a91f959cf09f60779f

See more details on using hashes here.

Provenance

The following attestation bundles were made for mapply-0.1.30-py3-none-any.whl:

Publisher: CD.yml on ddelange/mapply

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.2.0

2 files

0.1.31

2 files

This release

0.1.30 This release

2 files

0.1.29

2 files

0.1.28

2 files

0.1.27

2 files

0.1.26

2 files

0.1.25

2 files

0.1.24

2 files

0.1.23

2 files

0.1.22

2 files

0.1.21

2 files

0.1.20

2 files

0.1.19

2 files

0.1.18

2 files

0.1.17

2 files

0.1.16

2 files

0.1.15

2 files

0.1.14

2 files

0.1.13

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page