[](https://codeberg.org/Cs137/DynPaAc/src/branch/main/LICENSE)
[](https://pypi.org/project/dynpaac/)
[](https://pepy.tech/projects/dynpaac)
# 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.
```{warning}
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](https://pypi.org/project/dynpaac/)
via `pip`:
```sh
pip install dynpaac
```
The development version can be installed from
[the Git repository](https://codeberg.org/Cs137/DynPaAc) using `pip`:
```sh
# 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:
```python
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](https://codeberg.org/Cs137/DynPaAc/issues).
### Examples
#### Series Accessor - Basics
```python
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.
```python
# 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`](https://codeberg.org/Cs137/DynPaAc/src/branch/main/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](https://forgejo.org/docs/latest/user/pull-requests-and-git-flow/)
and follow the steps using this repository instead of the `example` repository.
Create your [pull request (PR)](https://codeberg.org/Cs137/DynPaAc/pulls) 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](https://python-poetry.org/docs/#installation).
```bash
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](https://codeberg.org/Cs137/DynPaAc/src/branch/main/LICENSE) file for details.
---
This package was created and is maintained by Christian Schreinemachers, (C) 2025.
Raw data
{
"_id": null,
"home_page": null,
"name": "dynpaac",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "pandas, series, accessor, dynamic, pandas-extension, dynamic-accessor",
"author": "Christian Schreinemachers (Cs137)",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/ef/dd/4ad7a314668aa1c2f587f0032b7963101ed7cf745c4e89e71019b200da7f/dynpaac-0.1.1.tar.gz",
"platform": null,
"description": "[](https://codeberg.org/Cs137/DynPaAc/src/branch/main/LICENSE)\n[](https://pypi.org/project/dynpaac/)\n[](https://pepy.tech/projects/dynpaac)\n\n\n# DynPaAc - Dynamic Pandas Accessors\n\nA Python package to dynamically create Pandas Series accessors for any classes.\n\nThis package allows you to dynamically access methods and properties of a target\nclass on a Pandas Series. By registering the accessor, you can apply the methods\nand properties of the class to any Series element. The return values of these\nmethods and properties are given back as a Pandas Series. The module includes\nvalidation to ensure that the Series elements are compatible with the class, and\nallows the exclusion of certain attributes. It also supports custom methods that\ncan be defined and applied to the Series alongside the methods and properties of\nthe target class.\n\n```{warning}\nThe project is currently in an early stage of development and changes in its behaviour might be introduced.\n```\n\n\n## Installation\n\nInstall the latest release of UnPaAc from [PyPI](https://pypi.org/project/dynpaac/)\nvia `pip`:\n\n```sh\npip install dynpaac\n```\n\nThe development version can be installed from\n[the Git repository](https://codeberg.org/Cs137/DynPaAc) using `pip`:\n\n```sh\n# Via https\npip install git+https://codeberg.org/Cs137/DynPaAc.git\n\n# Via ssh\npip install git+ssh://git@codeberg.org:Cs137/DynPaAc.git\n```\n\n\n## Usage\n\nThe package provides the `DynamicSeriesAccessor` class, a wrapper to access methods\nand properties of a target class from a pandas Series. The target class must be\ninitialisable with not more than one mandatory argument, and the arguments type\nmust correspond to the type of the series values.\n\nSince the `DynamicSeriesAccessor` class is initialised by pandas, there is the\n`create_dynamic_series_accessor()` function, which allows to preconfigure an\naccessor for a certain target class and register it as pandas series accessor.\nA `name` for the accessor and the desired `target_class` have to be defined.\nThe accessors can be called via the `name` attribute of series instances with\nvalues of valid input parameter types.\n\nMoreover, the exclusion of certain attributes is possible and the declaration of\ncustom methods that can be applied to the series alongside the methods and\nproperties of the target class is supported.\n\nThe creation function is all you need to dynamically create a series accessor for\na certain target class, simply import it as follows:\n\n```python\nfrom dynpaac.dynamic_series_accessor import create_dynamic_series_accessor\n```\n\nIf you have any questions or need assistance, feel free to\n[open an issue on the repository](https://codeberg.org/Cs137/DynPaAc/issues).\n\n### Examples\n\n#### Series Accessor - Basics\n\n```python\nimport pandas as pd\nfrom dynpaac.dynamic_series_accessor import create_dynamic_series_accessor\n\n# Define an example class\nclass MyClass:\n def __init__(self, value: str):\n self.value = value\n\n @property\n def length(self) -> int:\n return len(self.value)\n\n def add(self, string: str) -> str:\n return self.value + string\n\n# Create an accessor for the example class and define its name\ncreate_dynamic_series_accessor(\"mycls\", MyClass)\n\n# Create a pandas Series with strings\ndata = pd.Series([\"hello\", \"world\"])\n\n# Use the dynamic accessor to apply methods and properties of the example class\ndata.mycls.length # Access the 'length' property\ndata.mycls.add(\"!!!\") # Access the 'add' method\n```\n\n##### Output\n```\n0 5\n1 5\ndtype: int64\n\n0 hello!!!\n1 world!!!\ndtype: object\n```\n\n#### Series Accessor - Custom Methods\n\nYou can add your own methods to extend the functionality of the target class.\nOn the condition that they take the value of the series as the first argument.\nDeclare a dictionary of method names and callables as `custom_methods` when you create the accessor.\nThe custom methods are available through the declared names on the accessor.\n\n```python\n# Define an example custom method\ndef custom_method(value: str, prefix: str) -> str:\n return prefix + value\n\ncustom_methods={\"custom\": custom_method}\n\n# Recreate the accessor and include the custom method\ncreate_dynamic_series_accessor(\"mycls\", MyClass, custom_methods=custom_methods)\n\n# Use the dynamic accessor to apply the custom method\ndata.mycls.custom(\">>> \") # Access the 'custom_method'\n```\n\n##### Output\n```\n0 >>> hello\n1 >>> world\ndtype: object\n```\n\n\n## Changes\n\nAll notable changes to this project are documented in the file\n[`CHANGELOG.md`](https://codeberg.org/Cs137/DynPaAc/src/branch/main/CHANGELOG.md).\n\n\n## Contributing\n\nContributions to the `DynPaAc` package are very welcomed. Feel free to submit a\npull request, if you would like to contribute to the project. In case you are\nunfamiliar with the process, consult the\n[forgejo documentation](https://forgejo.org/docs/latest/user/pull-requests-and-git-flow/)\nand follow the steps using this repository instead of the `example` repository.\n\nCreate your [pull request (PR)](https://codeberg.org/Cs137/DynPaAc/pulls) to\ninform that you start working on a contribution. Provide a clear description\nof your envisaged changes and the motivation behind them, prefix the PR's title\nwith ``WIP: `` until your changes are finalised.\n\nAll kind of contributions are appreciated, whether they are\nbug fixes, new features, or improvements to the documentation.\n\n\n## Development\n\n### Installing for development\n\nTo install the package in development mode, clone the Git repository and install\nthe package using Poetry, as shown in the code block underneath. To install Poetry,\nwhich is required for virtual environment and dependency management, follow the\ninstructions on the [Poetry website](https://python-poetry.org/docs/#installation).\n\n```bash\ngit clone https://codeberg.org/Cs137/DynPaAc.git\ncd dynpaac\npoetry install\n```\n\nThis will create a virtual environment and install the package dependencies and\nthe package itself in editable mode, allowing you to make changes to the code and\nsee the effects immediately in the corresponding virtual environment. Alternatively,\nyou can install it via `pip install -e` in an existing virtual environment.\n\n\n## License\n\nDynPaAc is open source software released under the MIT License.\nSee [LICENSE](https://codeberg.org/Cs137/DynPaAc/src/branch/main/LICENSE) file for details.\n\n---\n\nThis package was created and is maintained by Christian Schreinemachers, (C) 2025.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python package to dynamically create Pandas Series accessors for any classes.",
"version": "0.1.1",
"project_urls": {
"Changelog": "https://codeberg.org/Cs137/DynPaAc/src/branch/main/CHANGELOG.md",
"Issues": "https://codeberg.org/Cs137/DynPaAc/issues",
"Repository": "https://codeberg.org/Cs137/DynPaAc"
},
"split_keywords": [
"pandas",
" series",
" accessor",
" dynamic",
" pandas-extension",
" dynamic-accessor"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b6470f82d3a9ce2c92740802eb857f35d56a6412675917951e9eea1d08b9115f",
"md5": "575e1530e3044687205bd0c124f1ae19",
"sha256": "e88d5125f38b06fc0bed69a032ac55682ee8834753ffbe2da07ea3bbae921a61"
},
"downloads": -1,
"filename": "dynpaac-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "575e1530e3044687205bd0c124f1ae19",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 7118,
"upload_time": "2025-02-11T13:25:59",
"upload_time_iso_8601": "2025-02-11T13:25:59.618183Z",
"url": "https://files.pythonhosted.org/packages/b6/47/0f82d3a9ce2c92740802eb857f35d56a6412675917951e9eea1d08b9115f/dynpaac-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "efdd4ad7a314668aa1c2f587f0032b7963101ed7cf745c4e89e71019b200da7f",
"md5": "56cd7cb82d037363732f723a1c59c568",
"sha256": "94b53142b205a8e8b6f98a53db49c859492ef76f6736ca134594ddfb5a496ff2"
},
"downloads": -1,
"filename": "dynpaac-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "56cd7cb82d037363732f723a1c59c568",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 6509,
"upload_time": "2025-02-11T13:26:01",
"upload_time_iso_8601": "2025-02-11T13:26:01.457128Z",
"url": "https://files.pythonhosted.org/packages/ef/dd/4ad7a314668aa1c2f587f0032b7963101ed7cf745c4e89e71019b200da7f/dynpaac-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-11 13:26:01",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": true,
"codeberg_user": "Cs137",
"codeberg_project": "DynPaAc",
"lcname": "dynpaac"
}