Skip to main content

License PyPI version PyPI Downloads

DynPaAc - Dynamic Pandas Accessors

A Python package to dynamically create Pandas Series accessors for any classes.

This package allows you to dynamically access methods and properties of a target class on a Pandas Series. By registering the accessor, you can apply the methods and properties of the class to any Series element. The return values of these methods and properties are given back as a Pandas Series. The module includes validation to ensure that the Series elements are compatible with the class, and allows the exclusion of certain attributes. It also supports custom methods that can be defined and applied to the Series alongside the methods and properties of the target class.

The project is currently in an early stage of development and changes in its behaviour might be introduced.

Installation

Install the latest release of UnPaAc from PyPI via pip:

pip install dynpaac

The development version can be installed from the Git repository using pip:

# Via https
pip install git+https://codeberg.org/Cs137/DynPaAc.git

# Via ssh
pip install git+ssh://git@codeberg.org:Cs137/DynPaAc.git

Usage

The package provides the DynamicSeriesAccessor class, a wrapper to access methods and properties of a target class from a pandas Series. The target class must be initialisable with not more than one mandatory argument, and the arguments type must correspond to the type of the series values.

Since the DynamicSeriesAccessor class is initialised by pandas, there is the create_dynamic_series_accessor() function, which allows to preconfigure an accessor for a certain target class and register it as pandas series accessor. A name for the accessor and the desired target_class have to be defined. The accessors can be called via the name attribute of series instances with values of valid input parameter types.

Moreover, the exclusion of certain attributes is possible and the declaration of custom methods that can be applied to the series alongside the methods and properties of the target class is supported.

The creation function is all you need to dynamically create a series accessor for a certain target class, simply import it as follows:

from dynpaac.dynamic_series_accessor import create_dynamic_series_accessor

If you have any questions or need assistance, feel free to open an issue on the repository.

Examples

Series Accessor - Basics

import pandas as pd
from dynpaac.dynamic_series_accessor import create_dynamic_series_accessor

# Define an example class
class MyClass:
    def __init__(self, value: str):
        self.value = value

    @property
    def length(self) -> int:
        return len(self.value)

    def add(self, string: str) -> str:
        return self.value + string

# Create an accessor for the example class and define its name
create_dynamic_series_accessor("mycls", MyClass)

# Create a pandas Series with strings
data = pd.Series(["hello", "world"])

# Use the dynamic accessor to apply methods and properties of the example class
data.mycls.length      # Access the 'length' property
data.mycls.add("!!!")  # Access the 'add' method
Output
0    5
1    5
dtype: int64

0    hello!!!
1    world!!!
dtype: object

Series Accessor - Custom Methods

You can add your own methods to extend the functionality of the target class. On the condition that they take the value of the series as the first argument. Declare a dictionary of method names and callables as custom_methods when you create the accessor. The custom methods are available through the declared names on the accessor.

# Define an example custom method
def custom_method(value: str, prefix: str) -> str:
    return prefix + value

custom_methods={"custom": custom_method}

# Recreate the accessor and include the custom method
create_dynamic_series_accessor("mycls", MyClass, custom_methods=custom_methods)

# Use the dynamic accessor to apply the custom method
data.mycls.custom(">>> ")  # Access the 'custom_method'
Output
0    >>> hello
1    >>> world
dtype: object

Changes

All notable changes to this project are documented in the file CHANGELOG.md.

Contributing

Contributions to the DynPaAc package are very welcomed. Feel free to submit a pull request, if you would like to contribute to the project. In case you are unfamiliar with the process, consult the forgejo documentation and follow the steps using this repository instead of the example repository.

Create your pull request (PR) to inform that you start working on a contribution. Provide a clear description of your envisaged changes and the motivation behind them, prefix the PR's title with WIP: until your changes are finalised.

All kind of contributions are appreciated, whether they are bug fixes, new features, or improvements to the documentation.

Development

Installing for development

To install the package in development mode, clone the Git repository and install the package using Poetry, as shown in the code block underneath. To install Poetry, which is required for virtual environment and dependency management, follow the instructions on the Poetry website.

git clone https://codeberg.org/Cs137/DynPaAc.git
cd dynpaac
poetry install

This will create a virtual environment and install the package dependencies and the package itself in editable mode, allowing you to make changes to the code and see the effects immediately in the corresponding virtual environment. Alternatively, you can install it via pip install -e in an existing virtual environment.

License

DynPaAc is open source software released under the MIT License. See LICENSE file for details.


This package was created and is maintained by Christian Schreinemachers, (C) 2025.

Metadata

Release files for dynpaac 0.1.1

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

Source distribution (sdist)

Source distribution for dynpaac 0.1.1
File Size Uploaded Provenance
dynpaac-0.1.1.tar.gz 6.5 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 13.6 kB

Release files / dynpaac-0.1.1.tar.gz

Download URL dynpaac-0.1.1.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
94b53142b205a8e8b6f98a53db49c859492ef76f6736ca134594ddfb5a496ff2
BLAKE2b-256 checksum
How to use checksums
efdd4ad7a314668aa1c2f587f0032b7963101ed7cf745c4e89e71019b200da7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.13.1 Linux/6.13.1-arch2-1

Release files / dynpaac-0.1.1-py3-none-any.whl

Download URL dynpaac-0.1.1-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e88d5125f38b06fc0bed69a032ac55682ee8834753ffbe2da07ea3bbae921a61
BLAKE2b-256 checksum
How to use checksums
b6470f82d3a9ce2c92740802eb857f35d56a6412675917951e9eea1d08b9115f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.13.1 Linux/6.13.1-arch2-1

Security for dynpaac 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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