Name | prd JSON |
Version |
0.3.0
JSON |
| download |
home_page | |
Summary | Idiomatic implementation of a Python function that calculates the product of the items from an iterable. |
upload_time | 2023-05-25 21:53:38 |
maintainer | |
docs_url | None |
author | Andrei Lapets |
requires_python | >=3.7 |
license | MIT |
keywords |
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
===
prd
===
Idiomatic implementation of a Python function that calculates the product of the items from an iterable.
|pypi| |readthedocs| |actions| |coveralls|
.. |pypi| image:: https://badge.fury.io/py/prd.svg
:target: https://badge.fury.io/py/prd
:alt: PyPI version and link.
.. |readthedocs| image:: https://readthedocs.org/projects/prd/badge/?version=latest
:target: https://prd.readthedocs.io/en/latest/?badge=latest
:alt: Read the Docs documentation status.
.. |actions| image:: https://github.com/lapets/prd/actions/workflows/lint-test-cover-docs.yml/badge.svg
:target: https://github.com/lapets/prd/actions/workflows/lint-test-cover-docs.yml
:alt: GitHub Actions status.
.. |coveralls| image:: https://coveralls.io/repos/github/lapets/prd/badge.svg?branch=main
:target: https://coveralls.io/github/lapets/prd?branch=main
:alt: Coveralls test coverage summary.
Purpose
-------
.. |sum| replace:: ``sum``
.. _sum: https://docs.python.org/3/library/functions.html#sum
.. |math_sum| replace:: ``math.sum``
.. _math_sum: https://docs.python.org/3/library/math.html#math.prod
.. |functools_reduce| replace:: ``functools.reduce``
.. _functools_reduce: https://docs.python.org/3/library/functools.html#functools.reduce
.. |mul| replace:: ``__mul__``
.. _mul: https://docs.python.org/3/reference/datamodel.html#object.__mul__
A built-in product function that would complement the |sum|_ function was `rejected <https://bugs.python.org/issue1093>`__, and the built-in |math_sum|_ function does not accept iterables that contain values of non-numeric types. This library exports an idiomatic implementation (using |functools_reduce|_) of a product function that can operate on iterables that contain objects of any type for which the multiplication operation is defined (*e.g.*, via a definition of the |mul|_ method).
Installation and Usage
----------------------
This library is available as a `package on PyPI <https://pypi.org/project/prd>`__:
.. code-block:: bash
python -m pip install prd
The library can be imported in the usual ways:
.. code-block:: python
import prd
from prd import prd
Examples
^^^^^^^^
.. |operator_mul| replace:: ``operator.mul``
.. _operator_mul: https://docs.python.org/3/library/operator.html#operator.mul
This library exports an idiomatic implementation of a product function (an analog of -- and complement to -- the built-in |sum|_ function). This function applies the built-in multiplication operator |operator_mul|_ to all of the items from the supplied iterable:
.. code-block:: python
>>> prd([1, 2, 3, 4])
24
>>> prd([2])
2
>>> prd([1.2, 3.4, 5.6])
22.848
>>> prd([])
1
The function is compatible with objects for which the built-in multiplication operator is defined:
.. code-block:: python
>>> class var(str):
... def __mul__(self, other):
... return self + ' * ' + other
... def __rmul__(self, other):
... return other + ' * ' + self
>>> prd([var('b'), var('c'), var('d')], var('a'))
'a * b * c * d'
The ``start`` parameter and the elements found in the iterable can be of different types. It is only required that the output of the multiplication operation can by multiplied with the next element from the iterable:
.. code-block:: python
>>> prd([], 'a')
'a'
>>> prd([1, 2, 3], 'a')
'aaaaaa'
>>> prd(['a', 3], 2)
'aaaaaa'
Development
-----------
All installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements <https://peps.python.org/pep-0621>`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip <https://pypi.org/project/pip>`__:
.. code-block:: bash
python -m pip install .[docs,lint]
Documentation
^^^^^^^^^^^^^
The documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__:
.. code-block:: bash
python -m pip install .[docs]
cd docs
sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html
Testing and Conventions
^^^^^^^^^^^^^^^^^^^^^^^
All unit tests are executed and their coverage is measured when using `pytest <https://docs.pytest.org>`__ (see the ``pyproject.toml`` file for configuration details):
.. code-block:: bash
python -m pip install .[test]
python -m pytest
Alternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`__:
.. code-block:: bash
python src/prd/prd.py -v
Style conventions are enforced using `Pylint <https://pylint.readthedocs.io>`__:
.. code-block:: bash
python -m pip install .[lint]
python -m pylint src/prd
Contributions
^^^^^^^^^^^^^
In order to contribute to the source code, open an issue or submit a pull request on the `GitHub page <https://github.com/lapets/prd>`__ for this library.
Versioning
^^^^^^^^^^
The version number format for this library and the changes to the library associated with version number increments conform with `Semantic Versioning 2.0.0 <https://semver.org/#semantic-versioning-200>`__.
Publishing
^^^^^^^^^^
This library can be published as a `package on PyPI <https://pypi.org/project/prd>`__ by a package maintainer. First, install the dependencies required for packaging and publishing:
.. code-block:: bash
python -m pip install .[publish]
Ensure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ``?.?.?`` with the version number):
.. code-block:: bash
git tag ?.?.?
git push origin ?.?.?
Remove any old build/distribution files. Then, package the source into a distribution archive:
.. code-block:: bash
rm -rf build dist src/*.egg-info
python -m build --sdist --wheel .
Finally, upload the package distribution archive to `PyPI <https://pypi.org>`__:
.. code-block:: bash
python -m twine upload dist/*
Raw data
{
"_id": null,
"home_page": "",
"name": "prd",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Andrei Lapets",
"author_email": "a@lapets.io",
"download_url": "https://files.pythonhosted.org/packages/ce/81/e44b05490782e69246d452e49375763bfcd0bd3a711c7b666850cc5597ab/prd-0.3.0.tar.gz",
"platform": null,
"description": "===\r\nprd\r\n===\r\n\r\nIdiomatic implementation of a Python function that calculates the product of the items from an iterable.\r\n\r\n|pypi| |readthedocs| |actions| |coveralls|\r\n\r\n.. |pypi| image:: https://badge.fury.io/py/prd.svg\r\n :target: https://badge.fury.io/py/prd\r\n :alt: PyPI version and link.\r\n\r\n.. |readthedocs| image:: https://readthedocs.org/projects/prd/badge/?version=latest\r\n :target: https://prd.readthedocs.io/en/latest/?badge=latest\r\n :alt: Read the Docs documentation status.\r\n\r\n.. |actions| image:: https://github.com/lapets/prd/actions/workflows/lint-test-cover-docs.yml/badge.svg\r\n :target: https://github.com/lapets/prd/actions/workflows/lint-test-cover-docs.yml\r\n :alt: GitHub Actions status.\r\n\r\n.. |coveralls| image:: https://coveralls.io/repos/github/lapets/prd/badge.svg?branch=main\r\n :target: https://coveralls.io/github/lapets/prd?branch=main\r\n :alt: Coveralls test coverage summary.\r\n\r\nPurpose\r\n-------\r\n\r\n.. |sum| replace:: ``sum``\r\n.. _sum: https://docs.python.org/3/library/functions.html#sum\r\n\r\n.. |math_sum| replace:: ``math.sum``\r\n.. _math_sum: https://docs.python.org/3/library/math.html#math.prod\r\n\r\n.. |functools_reduce| replace:: ``functools.reduce``\r\n.. _functools_reduce: https://docs.python.org/3/library/functools.html#functools.reduce\r\n\r\n.. |mul| replace:: ``__mul__``\r\n.. _mul: https://docs.python.org/3/reference/datamodel.html#object.__mul__\r\n\r\nA built-in product function that would complement the |sum|_ function was `rejected <https://bugs.python.org/issue1093>`__, and the built-in |math_sum|_ function does not accept iterables that contain values of non-numeric types. This library exports an idiomatic implementation (using |functools_reduce|_) of a product function that can operate on iterables that contain objects of any type for which the multiplication operation is defined (*e.g.*, via a definition of the |mul|_ method). \r\n\r\nInstallation and Usage\r\n----------------------\r\nThis library is available as a `package on PyPI <https://pypi.org/project/prd>`__:\r\n\r\n.. code-block:: bash\r\n\r\n python -m pip install prd\r\n\r\nThe library can be imported in the usual ways:\r\n\r\n.. code-block:: python\r\n\r\n import prd\r\n from prd import prd\r\n\r\nExamples\r\n^^^^^^^^\r\n\r\n.. |operator_mul| replace:: ``operator.mul``\r\n.. _operator_mul: https://docs.python.org/3/library/operator.html#operator.mul\r\n\r\nThis library exports an idiomatic implementation of a product function (an analog of -- and complement to -- the built-in |sum|_ function). This function applies the built-in multiplication operator |operator_mul|_ to all of the items from the supplied iterable:\r\n\r\n.. code-block:: python\r\n\r\n >>> prd([1, 2, 3, 4])\r\n 24\r\n >>> prd([2])\r\n 2\r\n >>> prd([1.2, 3.4, 5.6])\r\n 22.848\r\n >>> prd([])\r\n 1\r\n\r\nThe function is compatible with objects for which the built-in multiplication operator is defined:\r\n\r\n.. code-block:: python\r\n\r\n >>> class var(str):\r\n ... def __mul__(self, other):\r\n ... return self + ' * ' + other\r\n ... def __rmul__(self, other):\r\n ... return other + ' * ' + self\r\n >>> prd([var('b'), var('c'), var('d')], var('a'))\r\n 'a * b * c * d'\r\n\r\nThe ``start`` parameter and the elements found in the iterable can be of different types. It is only required that the output of the multiplication operation can by multiplied with the next element from the iterable:\r\n\r\n.. code-block:: python\r\n\r\n >>> prd([], 'a')\r\n 'a'\r\n >>> prd([1, 2, 3], 'a')\r\n 'aaaaaa'\r\n >>> prd(['a', 3], 2)\r\n 'aaaaaa'\r\n\r\nDevelopment\r\n-----------\r\nAll installation and development dependencies are fully specified in ``pyproject.toml``. The ``project.optional-dependencies`` object is used to `specify optional requirements <https://peps.python.org/pep-0621>`__ for various development tasks. This makes it possible to specify additional options (such as ``docs``, ``lint``, and so on) when performing installation using `pip <https://pypi.org/project/pip>`__:\r\n\r\n.. code-block:: bash\r\n\r\n python -m pip install .[docs,lint]\r\n\r\nDocumentation\r\n^^^^^^^^^^^^^\r\nThe documentation can be generated automatically from the source files using `Sphinx <https://www.sphinx-doc.org>`__:\r\n\r\n.. code-block:: bash\r\n\r\n python -m pip install .[docs]\r\n cd docs\r\n sphinx-apidoc -f -E --templatedir=_templates -o _source .. && make html\r\n\r\nTesting and Conventions\r\n^^^^^^^^^^^^^^^^^^^^^^^\r\nAll unit tests are executed and their coverage is measured when using `pytest <https://docs.pytest.org>`__ (see the ``pyproject.toml`` file for configuration details):\r\n\r\n.. code-block:: bash\r\n\r\n python -m pip install .[test]\r\n python -m pytest\r\n\r\nAlternatively, all unit tests are included in the module itself and can be executed using `doctest <https://docs.python.org/3/library/doctest.html>`__:\r\n\r\n.. code-block:: bash\r\n\r\n python src/prd/prd.py -v\r\n\r\nStyle conventions are enforced using `Pylint <https://pylint.readthedocs.io>`__:\r\n\r\n.. code-block:: bash\r\n\r\n python -m pip install .[lint]\r\n python -m pylint src/prd\r\n\r\nContributions\r\n^^^^^^^^^^^^^\r\nIn order to contribute to the source code, open an issue or submit a pull request on the `GitHub page <https://github.com/lapets/prd>`__ for this library.\r\n\r\nVersioning\r\n^^^^^^^^^^\r\nThe version number format for this library and the changes to the library associated with version number increments conform with `Semantic Versioning 2.0.0 <https://semver.org/#semantic-versioning-200>`__.\r\n\r\nPublishing\r\n^^^^^^^^^^\r\nThis library can be published as a `package on PyPI <https://pypi.org/project/prd>`__ by a package maintainer. First, install the dependencies required for packaging and publishing:\r\n\r\n.. code-block:: bash\r\n\r\n python -m pip install .[publish]\r\n\r\nEnsure that the correct version number appears in ``pyproject.toml``, and that any links in this README document to the Read the Docs documentation of this package (or its dependencies) have appropriate version numbers. Also ensure that the Read the Docs project for this library has an `automation rule <https://docs.readthedocs.io/en/stable/automation-rules.html>`__ that activates and sets as the default all tagged versions. Create and push a tag for this version (replacing ``?.?.?`` with the version number):\r\n\r\n.. code-block:: bash\r\n\r\n git tag ?.?.?\r\n git push origin ?.?.?\r\n\r\nRemove any old build/distribution files. Then, package the source into a distribution archive:\r\n\r\n.. code-block:: bash\r\n\r\n rm -rf build dist src/*.egg-info\r\n python -m build --sdist --wheel .\r\n\r\nFinally, upload the package distribution archive to `PyPI <https://pypi.org>`__:\r\n\r\n.. code-block:: bash\r\n\r\n python -m twine upload dist/*\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Idiomatic implementation of a Python function that calculates the product of the items from an iterable.",
"version": "0.3.0",
"project_urls": {
"Documentation": "https://prd.readthedocs.io",
"Repository": "https://github.com/lapets/prd"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d832145c8ca234cd6ffc523ead5181d50038e64fa8bf688a59e110817b214aff",
"md5": "75a9a8d4ba9e4d425004d2dc437513f5",
"sha256": "0065cabaf58ef383aa9a354a1739626145bfb1aa345bf2137ced9b9b4f00ef90"
},
"downloads": -1,
"filename": "prd-0.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "75a9a8d4ba9e4d425004d2dc437513f5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 5590,
"upload_time": "2023-05-25T21:53:36",
"upload_time_iso_8601": "2023-05-25T21:53:36.395352Z",
"url": "https://files.pythonhosted.org/packages/d8/32/145c8ca234cd6ffc523ead5181d50038e64fa8bf688a59e110817b214aff/prd-0.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ce81e44b05490782e69246d452e49375763bfcd0bd3a711c7b666850cc5597ab",
"md5": "789d65120cd42aeee0186a05242c40e7",
"sha256": "8e240f162e58eab2a75ccd6352ffde9e6c29eb092d33ceea9773dce9506f7648"
},
"downloads": -1,
"filename": "prd-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "789d65120cd42aeee0186a05242c40e7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 5359,
"upload_time": "2023-05-25T21:53:38",
"upload_time_iso_8601": "2023-05-25T21:53:38.021673Z",
"url": "https://files.pythonhosted.org/packages/ce/81/e44b05490782e69246d452e49375763bfcd0bd3a711c7b666850cc5597ab/prd-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-25 21:53:38",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lapets",
"github_project": "prd",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "prd"
}