Skip to main content

mapply

build codecov pypi Version python downloads black

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.

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

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

Metadata

Release files for mapply 0.1.24

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mapply 0.1.24
File Size Uploaded
mapply-0.1.24.tar.gz 10.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mapply 0.1.24
File Interpreter ABI Platform
mapply-0.1.24-py3-none-any.whl Python 3 none any Details

Total release size: 23.7 kB

Release files / mapply-0.1.24.tar.gz

Download URL mapply-0.1.24.tar.gz
Size 10.1 kB
Tags Source
SHA-256 checksum
How to use checksums
156a3d2b5a112cd2721fd6ff48c8ed5de9c12530bf9630a0827bb0a5e94c665c
BLAKE2b-256 checksum
How to use checksums
f9960b2e607494d7bd79f2ef549bdedee52f6270fcc703c1d12ceb2f531780cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / mapply-0.1.24-py3-none-any.whl

Download URL mapply-0.1.24-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7f5ff7ff0385917d07faf3cf2fe196c25f7409550019d5335113885d42b74b7
BLAKE2b-256 checksum
How to use checksums
a637ecad6eddf43dd6bb4c61a8933ac7617d8c0ab931f509102692986fed18d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.2 CPython/3.11.7
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