paramcheckup


Nameparamcheckup JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryCheck whether the parameters received by a function are correct
upload_time2023-11-02 18:52:26
maintainer
docs_urlNone
author
requires_python>=3.10
licenseBSD 3-Clause License Copyright (c) 2023, paramcheckup 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.
keywords type check warnings
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="https://raw.githubusercontent.com/puzzle-in-a-mug/paramcheckup/main/docs/_static/logo.png" align="right" />

# paramcheckup

<img srd="https://img.shields.io/badge/Python-FFD43B?style=for-the-badge&logo=python&logoColor=blue"> <img src="https://img.shields.io/badge/numpy-%23013243.svg?style=for-the-badge&logo=numpy&logoColor=white"> <img src="https://img.shields.io/badge/Pandas-2C2D72?style=for-the-badge&logo=pandas&logoColor=white"> <img src="https://img.shields.io/badge/Matplotlib-%23ffffff.svg?style=for-the-badge&logo=Matplotlib&logoColor=black"> <img src="https://img.shields.io/badge/License-BSD%203--Clause-blue.svg">

This package has a collection of functions that check whether the parameter received by a function is of a certain type, returning ``True`` if the input is as expected or ``raising an error`` that indicates what the problem is.



## Install

```
pip install paramcheckup
```



## Example 1


```python
import numpy as np
from scipy import stats
```

Assume a function ``t_test()`` that applies one sample Student's t test to compare means (two sided). This function receives three parameters, which are ``x_data``, ``mu`` and ``alpha``.

```python
def t_test(x_data, mu, alpha):
    tcalc = (x_data.mean() - mu)*np.sqrt(x_data.size)/(x_data.std(ddof=1))
    t_critical = stats.t.ppf(1-alpha/2, x_data.size - 1)
    p_value = (1 - stats.t.cdf(np.abs(tcalc), x_data.size - 1))*2
    if p_value < alpha:
        conclusion = "Reject H0"
    else:
        conclusion = "Fail to reject H0"
    return tcalc, t_critical, p_value, conclusion
```

The ``t_test`` function strongly depends on the ``x_data`` parameter being a one-dimensional ``NumpyArray``. The ``types.is_numpy(value, param_name, func_name)`` function can checks whether this is ``True``:



```python
from paramcheckup import types
def t_test(x_data, mu, alpha):
    types.is_numpy(x_data, "x_data", "t_test")
    
    tcalc = (x_data.mean() - mu)*np.sqrt(x_data)/(x_data.std(ddof=1))
    t_critical = stats.t.ppf(1-alpha/2, x_data.size - 1)
    p_value = (1 - stats.t.cdf(np.abs(tcalc), x_data.size - 1))*2
    if p_value < alpha:
        conclusion = "Reject H0"
    else:
        conclusion = "Fail to reject H0"
    return tcalc, t_critical, p_value, conclusion
```

If the user passes a ``NumpyArray`` as input for ``x_data``, the result of ``types.is_numpy`` function will be ``True`` and the calculation will be performed.

```python
x = np.array([1.24, 1.3, 1.11])
result = t_test(x, 3, 0.05)
print(result)
(-31.80244895786038, 4.302652729911275, 0.0009872686643235262, 'Reject H0')
```

However, if you use a ``list`` instead of ``NumpyArray``, an ``TypeError`` will be raised indicating what the error is:

```python
x = [1.24, 1.3, 1.11]
result = t_test(x, 3, 0.05)
The parameter 'x_data' in function 't_test' must be of type *numpy.ndarray*, but its type is *list*.
```

The Traceback error is also displayed:

```
Traceback (most recent call last):
  File "...\main.py", line 21, in <module>
    result = t_test(x, 3, 0.05)
  File "...\main.py", line 8, in t_test
    types.is_numpy(x_data, "x_data", "t_test")
  File "...\venv\lib\site-packages\paramcheckup\types.py", line 436, in is_numpy
    raise TypeError("NotNumPyError")
TypeError: NotNumPyError
```

> In future releases, the ``Traceback`` will be optional



## Example 2

The ``alpha`` parameter indicates the level of significance that should be adopted for the test. It is a value that varies between ``0`` and ``1``. To limit the range of values, you can use the ``numbers.is_between_a_and_b()`` function:

```python
from paramcheckup import types, numbers

def t_test(x_data, mu, alpha):
    types.is_numpy(x_data, "x_data", "t_test")
    numbers.is_between_a_and_b(alpha, 0, 1, "alpha", "t_test", inclusive=False)
    tcalc = (x_data.mean() - mu)*np.sqrt(x_data.size)/(x_data.std(ddof=1))
    t_critical = stats.t.ppf(1-alpha/2, x_data.size - 1)
    p_value = (1 - stats.t.cdf(np.abs(tcalc), x_data.size - 1))*2
    if p_value < alpha:
        conclusion = "Reject H0"
    else:
        conclusion = "Fail to reject H0"
    return tcalc, t_critical, p_value, conclusion


x = np.array([1.24, 1.3, 1.11])
alpha = 1.05
result = t_test(x, 3, alpha)
The value of parameter 'alpha' in function 't_test' must be within the range of 0 < value < 1, but it is '1.05'.
```


> ``Traceback`` ommited


Note that the ``inclusive=False`` parameter causes the limits to be open, which makes sense for the significance level.


## License

- [BSD 3-Clause License](https://github.com/puzzle-in-a-mug/paramcheckup/blob/main/LICENSE)





            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "paramcheckup",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "type,check,warnings",
    "author": "",
    "author_email": "Anderson Marcos Dias Canteli <andersonmdcanteli@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/37/a4/0d7e184c77d1a437c04b90a9be0039a13eb6871c13b713a4cf2ed0c10efe/paramcheckup-1.0.0.tar.gz",
    "platform": null,
    "description": "<img src=\"https://raw.githubusercontent.com/puzzle-in-a-mug/paramcheckup/main/docs/_static/logo.png\" align=\"right\" />\r\n\r\n# paramcheckup\r\n\r\n<img srd=\"https://img.shields.io/badge/Python-FFD43B?style=for-the-badge&logo=python&logoColor=blue\"> <img src=\"https://img.shields.io/badge/numpy-%23013243.svg?style=for-the-badge&logo=numpy&logoColor=white\"> <img src=\"https://img.shields.io/badge/Pandas-2C2D72?style=for-the-badge&logo=pandas&logoColor=white\"> <img src=\"https://img.shields.io/badge/Matplotlib-%23ffffff.svg?style=for-the-badge&logo=Matplotlib&logoColor=black\"> <img src=\"https://img.shields.io/badge/License-BSD%203--Clause-blue.svg\">\r\n\r\nThis package has a collection of functions that check whether the parameter received by a function is of a certain type, returning ``True`` if the input is as expected or ``raising an error`` that indicates what the problem is.\r\n\r\n\r\n\r\n## Install\r\n\r\n```\r\npip install paramcheckup\r\n```\r\n\r\n\r\n\r\n## Example 1\r\n\r\n\r\n```python\r\nimport numpy as np\r\nfrom scipy import stats\r\n```\r\n\r\nAssume a function ``t_test()`` that applies one sample Student's t test to compare means (two sided). This function receives three parameters, which are ``x_data``, ``mu`` and ``alpha``.\r\n\r\n```python\r\ndef t_test(x_data, mu, alpha):\r\n    tcalc = (x_data.mean() - mu)*np.sqrt(x_data.size)/(x_data.std(ddof=1))\r\n    t_critical = stats.t.ppf(1-alpha/2, x_data.size - 1)\r\n    p_value = (1 - stats.t.cdf(np.abs(tcalc), x_data.size - 1))*2\r\n    if p_value < alpha:\r\n        conclusion = \"Reject H0\"\r\n    else:\r\n        conclusion = \"Fail to reject H0\"\r\n    return tcalc, t_critical, p_value, conclusion\r\n```\r\n\r\nThe ``t_test`` function strongly depends on the ``x_data`` parameter being a one-dimensional ``NumpyArray``. The ``types.is_numpy(value, param_name, func_name)`` function can checks whether this is ``True``:\r\n\r\n\r\n\r\n```python\r\nfrom paramcheckup import types\r\ndef t_test(x_data, mu, alpha):\r\n    types.is_numpy(x_data, \"x_data\", \"t_test\")\r\n    \r\n    tcalc = (x_data.mean() - mu)*np.sqrt(x_data)/(x_data.std(ddof=1))\r\n    t_critical = stats.t.ppf(1-alpha/2, x_data.size - 1)\r\n    p_value = (1 - stats.t.cdf(np.abs(tcalc), x_data.size - 1))*2\r\n    if p_value < alpha:\r\n        conclusion = \"Reject H0\"\r\n    else:\r\n        conclusion = \"Fail to reject H0\"\r\n    return tcalc, t_critical, p_value, conclusion\r\n```\r\n\r\nIf the user passes a ``NumpyArray`` as input for ``x_data``, the result of ``types.is_numpy`` function will be ``True`` and the calculation will be performed.\r\n\r\n```python\r\nx = np.array([1.24, 1.3, 1.11])\r\nresult = t_test(x, 3, 0.05)\r\nprint(result)\r\n(-31.80244895786038, 4.302652729911275, 0.0009872686643235262, 'Reject H0')\r\n```\r\n\r\nHowever, if you use a ``list`` instead of ``NumpyArray``, an ``TypeError`` will be raised indicating what the error is:\r\n\r\n```python\r\nx = [1.24, 1.3, 1.11]\r\nresult = t_test(x, 3, 0.05)\r\nThe parameter 'x_data' in function 't_test' must be of type *numpy.ndarray*, but its type is *list*.\r\n```\r\n\r\nThe Traceback error is also displayed:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"...\\main.py\", line 21, in <module>\r\n    result = t_test(x, 3, 0.05)\r\n  File \"...\\main.py\", line 8, in t_test\r\n    types.is_numpy(x_data, \"x_data\", \"t_test\")\r\n  File \"...\\venv\\lib\\site-packages\\paramcheckup\\types.py\", line 436, in is_numpy\r\n    raise TypeError(\"NotNumPyError\")\r\nTypeError: NotNumPyError\r\n```\r\n\r\n> In future releases, the ``Traceback`` will be optional\r\n\r\n\r\n\r\n## Example 2\r\n\r\nThe ``alpha`` parameter indicates the level of significance that should be adopted for the test. It is a value that varies between ``0`` and ``1``. To limit the range of values, you can use the ``numbers.is_between_a_and_b()`` function:\r\n\r\n```python\r\nfrom paramcheckup import types, numbers\r\n\r\ndef t_test(x_data, mu, alpha):\r\n    types.is_numpy(x_data, \"x_data\", \"t_test\")\r\n    numbers.is_between_a_and_b(alpha, 0, 1, \"alpha\", \"t_test\", inclusive=False)\r\n    tcalc = (x_data.mean() - mu)*np.sqrt(x_data.size)/(x_data.std(ddof=1))\r\n    t_critical = stats.t.ppf(1-alpha/2, x_data.size - 1)\r\n    p_value = (1 - stats.t.cdf(np.abs(tcalc), x_data.size - 1))*2\r\n    if p_value < alpha:\r\n        conclusion = \"Reject H0\"\r\n    else:\r\n        conclusion = \"Fail to reject H0\"\r\n    return tcalc, t_critical, p_value, conclusion\r\n\r\n\r\nx = np.array([1.24, 1.3, 1.11])\r\nalpha = 1.05\r\nresult = t_test(x, 3, alpha)\r\nThe value of parameter 'alpha' in function 't_test' must be within the range of 0 < value < 1, but it is '1.05'.\r\n```\r\n\r\n\r\n> ``Traceback`` ommited\r\n\r\n\r\nNote that the ``inclusive=False`` parameter causes the limits to be open, which makes sense for the significance level.\r\n\r\n\r\n## License\r\n\r\n- [BSD 3-Clause License](https://github.com/puzzle-in-a-mug/paramcheckup/blob/main/LICENSE)\r\n\r\n\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License  Copyright (c) 2023, paramcheckup  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. ",
    "summary": "Check whether the parameters received by a function are correct",
    "version": "1.0.0",
    "project_urls": {
        "Docs": "https://paramcheckup.readthedocs.io/en/latest/",
        "Source": "https://github.com/anderson-canteli/paramcheckup"
    },
    "split_keywords": [
        "type",
        "check",
        "warnings"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a039e82b762108603a136459679f7bfe23ad0ee17bda55b0f05ad19fe27f4a18",
                "md5": "38af41142edb831948fd8e08959d4610",
                "sha256": "6d1fb5bad5d8e99cb16789b32f450c1292937368deaa4c2dd9eef0a9defee4aa"
            },
            "downloads": -1,
            "filename": "paramcheckup-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "38af41142edb831948fd8e08959d4610",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 14596,
            "upload_time": "2023-11-02T18:52:24",
            "upload_time_iso_8601": "2023-11-02T18:52:24.230792Z",
            "url": "https://files.pythonhosted.org/packages/a0/39/e82b762108603a136459679f7bfe23ad0ee17bda55b0f05ad19fe27f4a18/paramcheckup-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "37a40d7e184c77d1a437c04b90a9be0039a13eb6871c13b713a4cf2ed0c10efe",
                "md5": "35e671002df8bef83f3dc416e491f302",
                "sha256": "2344aa2402e5a96150327fe59e0011a9f2a6ffc9c5728b81c3f495afb936bb3e"
            },
            "downloads": -1,
            "filename": "paramcheckup-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "35e671002df8bef83f3dc416e491f302",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 96211,
            "upload_time": "2023-11-02T18:52:26",
            "upload_time_iso_8601": "2023-11-02T18:52:26.590093Z",
            "url": "https://files.pythonhosted.org/packages/37/a4/0d7e184c77d1a437c04b90a9be0039a13eb6871c13b713a4cf2ed0c10efe/paramcheckup-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-02 18:52:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "anderson-canteli",
    "github_project": "paramcheckup",
    "github_not_found": true,
    "lcname": "paramcheckup"
}
        
Elapsed time: 0.14633s