https://github.com/bsdz/argcast
Automatically cast function parameters at run time based on their types.
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (8.6%) to scientific vocabulary
Repository
Automatically cast function parameters at run time based on their types.
Basic Info
- Host: GitHub
- Owner: bsdz
- License: mit
- Language: Python
- Default Branch: main
- Size: 6.84 KB
Statistics
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
- Releases: 1
Metadata Files
README.md
argcast - Run time function argument caster
Automatically cast function parameters at run time based on their types.
Installation
bash
pip install argcast
Usage
Below is an example usage:
```python from decimal import Decimal from enum import Enum
import numpy as np import pandas as pd
from argcast import coerce_params
class MatrixOp(Enum): INVERSE = 1 TRANSPOSE = 2
@classmethod
def get(cls, name):
return cls[name] if isinstance(name, str) else cls(name)
coerce = coerce_params({np.ndarray: np.array, MatrixOp: MatrixOp.get})
@coerce def f( a: np.ndarray, b: np.ndarray, k: np.float64, b_trans: MatrixOp ) -> pd.DataFrame:
if b_trans == MatrixOp.INVERSE:
b = np.linalg.inv(b)
elif b_trans == MatrixOp.TRANSPOSE:
b = b.T
return k * a @ b
f([[1, 2], [3, 4]], [[5, 6], [7, 8]], Decimal("2.0"), "TRANSPOSE")
returns pd.DataFrame([[34.0, 46.0], [78.0, 106.0]])
```
Limitations
1) Using this decorator will confuse type checkers like mypy and you might wish to place a top level comment in your module like:
```python
mypy: disable-error-code="return-value"
```
2) Although basic sequence and mapping types are supported, ie list|tuple|set[str|int|...] or dict[..., ...], many other types aren't (eg nested types list[list[...]] etc).
Development
Before commit run following format commands in project folder:
bash
poetry run black .
poetry run isort . --profile black
poetry run docformatter . --recursive --in-place --black
Owner
- Name: Blair Azzopardi
- Login: bsdz
- Kind: user
- Location: London
- Twitter: bsdzuk
- Repositories: 53
- Profile: https://github.com/bsdz
Amateur mathematician. I enjoy researching different fields from applied maths to number theory. I like building RaspberryPi projects. Quant developer by day.
GitHub Events
Total
- Push event: 1
Last Year
- Push event: 1
Packages
- Total packages: 1
-
Total downloads:
- pypi 29 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 3
- Total maintainers: 1
pypi.org: argcast
Automatically cast function parameters at run time based on their types.
- Documentation: https://argcast.readthedocs.io/
- License: mit
-
Latest release: 0.3.0
published about 1 year ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v3 composite
- wntrblm/nox main composite
- actions/checkout v4 composite
- actions/download-artifact v4 composite
- actions/setup-python v5 composite
- actions/upload-artifact v4 composite
- pypa/gh-action-pypi-publish release/v1 composite