dynpaac


Namedynpaac JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryAccessor for applying class methods and properties to Pandas Series.
upload_time2025-01-27 09:00:38
maintainerNone
docs_urlNone
authorChristian Schreinemachers (Cs137)
requires_python>=3.9
licenseMIT
keywords pandas series accessor dynamic pandas-extension dynamic-accessor
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![License](https://img.shields.io/pypi/l/dynpaac?color=blue)](https://codeberg.org/Cs137/DynPaAc/src/branch/main/LICENSE)
[![PyPI version](https://img.shields.io/pypi/v/dynpaac.svg)](https://pypi.org/project/dynpaac/)
[![PyPI Downloads](https://static.pepy.tech/badge/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

DynPaAc is not yet published on PyPI.
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 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).

### Example

```python
import pandas as pd
from dynpaac.dynamic_series_accessor import create_dynamic_series_accessor

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

def custom_method(x: str, prefix: str) -> str:
    return prefix + x

# Register the accessor and define its name
create_dynamic_series_accessor("mycls", MyClass, custom_methods={"custom": custom_method})

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

# Use the dynamic accessor to apply methods and properties
print(data.mycls.length)      # Access the 'length' property
print(data.mycls.add("!!!"))  # Access the 'add' method
print(data.mycls.custom(">>> "))  # Access the 'custom_method'
```

#### Output
```
0    5
1    5
dtype: int64

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

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/d4/16/63ecea3640bc22c6a220128704975a94e71aa0f75252ba764b6df744ffe6/dynpaac-0.1.0.tar.gz",
    "platform": null,
    "description": "[![License](https://img.shields.io/pypi/l/dynpaac?color=blue)](https://codeberg.org/Cs137/DynPaAc/src/branch/main/LICENSE)\n[![PyPI version](https://img.shields.io/pypi/v/dynpaac.svg)](https://pypi.org/project/dynpaac/)\n[![PyPI Downloads](https://static.pepy.tech/badge/dynpaac)](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\nDynPaAc is not yet published on PyPI.\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 argument, and the arguments type must correspond\nto 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### Example\n\n```python\nimport pandas as pd\nfrom dynpaac.dynamic_series_accessor import create_dynamic_series_accessor\n\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\ndef custom_method(x: str, prefix: str) -> str:\n    return prefix + x\n\n# Register the accessor and define its name\ncreate_dynamic_series_accessor(\"mycls\", MyClass, custom_methods={\"custom\": custom_method})\n\n# Create a pandas Series with strings\ndata = pd.Series([\"hello\", \"world\"])\n\n# Use the dynamic accessor to apply methods and properties\nprint(data.mycls.length)      # Access the 'length' property\nprint(data.mycls.add(\"!!!\"))  # Access the 'add' method\nprint(data.mycls.custom(\">>> \"))  # Access the 'custom_method'\n```\n\n#### Output\n```\n0    5\n1    5\ndtype: int64\n\n0    hello!!!\n1    world!!!\ndtype: object\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": "Accessor for applying class methods and properties to Pandas Series.",
    "version": "0.1.0",
    "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": "94979a5585434d83b6f3d70495d549c1c330f4c6855fdaa334778839489a8745",
                "md5": "021ed2fed362b07d0ecfb755debad4a2",
                "sha256": "8c9796899a7523e646fe778b6f7b9d9638588b1ffa4667729d4d5bf2f5328a9a"
            },
            "downloads": -1,
            "filename": "dynpaac-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "021ed2fed362b07d0ecfb755debad4a2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6283,
            "upload_time": "2025-01-27T09:00:37",
            "upload_time_iso_8601": "2025-01-27T09:00:37.603390Z",
            "url": "https://files.pythonhosted.org/packages/94/97/9a5585434d83b6f3d70495d549c1c330f4c6855fdaa334778839489a8745/dynpaac-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d41663ecea3640bc22c6a220128704975a94e71aa0f75252ba764b6df744ffe6",
                "md5": "1276111d4e269934f298e849fcb36ec8",
                "sha256": "efc386793ae6bfcae42a340e55b981ba582bfb31181d62d0d7fe8a20d87d5ee3"
            },
            "downloads": -1,
            "filename": "dynpaac-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1276111d4e269934f298e849fcb36ec8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 5689,
            "upload_time": "2025-01-27T09:00:38",
            "upload_time_iso_8601": "2025-01-27T09:00:38.808088Z",
            "url": "https://files.pythonhosted.org/packages/d4/16/63ecea3640bc22c6a220128704975a94e71aa0f75252ba764b6df744ffe6/dynpaac-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-27 09:00:38",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": true,
    "codeberg_user": "Cs137",
    "codeberg_project": "DynPaAc",
    "lcname": "dynpaac"
}
        
Elapsed time: 0.79101s