{
"info": {
"author": "Thomas Robitaille",
"author_email": "thomas.robitaille@gmail.com",
"bugtrack_url": null,
"classifiers": [],
"description": "Numerical properties for Python objects\n=======================================\n\n|Travis Build Status| |Coverage Status|\n\n**Please note:** this package is experimental and may still see some\nchanges to the API. If you have any suggestions for improving the API,\nplease open an issue!\n\nAbout\n-----\n\nThis simple module defines a descriptor class that can be used to define\nnumerical properties (scalar and n-dimensional arrays) on classes and\nprovide a way to validate these. Thus, instead of writing something\nlike:\n\n.. code:: python\n\n class Sphere(object):\n\n @property\n def radius(self):\n return self._radius\n \n @radius.setter\n def radius(self, value):\n if value <= 0:\n raise ValueError(\"Value should be strictly positive\")\n if not np.isscalar(value):\n raise TypeError(\"Value should be a scalar\")\n if not np.isreal(value):\n raise TypeError(\"Value should be numerical\")\n self._value = value\n\nfor each property you want to define, you can simply do:\n\n.. code:: python\n\n from numprops import NumericalProperty\n\n class Sphere(object):\n\n radius = NumericalProperty('radius', domain='strictly-positive', ndim=0)\n\nSupport is also included for checking the dimensionality and shape of\narrays (which includes converting tuples and lists to arrays\non-the-fly), as well as checking the units of quantities for the\n`astropy.units `__,\n`pint `__, and\n`quantities `__ unit frameworks.\n\nInstalling\n----------\n\nThis package is compatible with Python 2.6, 2.7, and 3.3 and later, and\nrequires `numpy `__. If you are interested in\ndoing unit validation, you will also need\n`astropy `__,\n`pint `__, or\n`quantities `__, depending on\nwhich unit framework you normally use.\n\nTo install, you can do:\n\n::\n\n pip install numprops\n\nYou can also bundle ``numprops.py`` into your package if you want to\navoid using an external dependency, but please be sure to keep the\ncopyright and the license for the file.\n\nUsing\n-----\n\nTo create self-validating numerical properties on a class, use the\n``NumericalProperty`` class:\n\n.. code:: python\n\n from numprops import NumericalProperty\n\n class Sphere(object):\n\n radius = NumericalProperty('radius', domain='strictly-positive', ndim=0)\n position = NumericalProperty('position', shape=(3,))\n\nWhen a property is set, it will be validated:\n\n.. code:: python\n\n >>> s = Sphere()\n >>> s.radius = 1.\n >>> s.radius = -3\n ...\n ValueError: radius should be strictly positive\n >>> s.radius = [1,2]\n ...\n TypeError: radius should be a scalar value\n >>> s.position = (1,2,3)\n >>> s.position = 3\n ...\n TypeError: position should be a 1-d sequence\n >>> s.position = (1,2,3,4)\n ...\n ValueError: position has incorrect length (expected 3 but found 4)\n\nThe following arguments to ``NumericalProperty`` are available (in\naddition to the property name):\n\n- ``ndim``: restrict the values to arrays with this number of dimension\n- ``shape``: restrict the values to arrays with this shape. If\n specified, ``ndim`` does not need to be given.\n- ``domain``: restrict the values to a particular domain - can be one\n of ``positive``, ``strictly-positive``, ``negative``,\n ``strictly-negative``, or a tuple representing a range of values.\n- ``default``: the default value to return, if not specified (defaults\n to ``None``)\n- ``convertible_to``: restrict the values to ones with units that would\n be convertible to a specific set of units (see section below)\n\nNote that tuples and lists will automatically get converted to Numpy\narrays, if they are considered valid.\n\nPhysical units\n--------------\n\nWhile ``NumericalProperty`` can be used for plain scalars and Numpy\narrays, it can also be used for scalars and arrays which have associated\nunits, with support for three popular unit handling units:\n`astropy.units `__,\n`pint `__, and\n`quantities `__.\n\nTo restrict a ``NumericalProperty`` to quantities with a certain type of\nunit, use the ``convertible_to`` option. This option takes units from\nany of these three unit packages, and will ensure that any value passed\nhas units equivalent (but not necessarily equal) to those specified with\nthe ``convertible_to`` option.\n\nIf the units passed to ``convertible_to`` are\n`astropy.units `__ units, then any\nvalue passed to the property should then be an\n`astropy.units `__ quantity. If the\nunits passed to ``convertible_to`` are\n`pint `__ units, then any quantity passed\nto the property should be a `pint `__\nproperty. And finally if the units passed to ``convertible_to`` are\n`quantities `__ units, then any\nquantity passed to the property should be a\n`quantities `__ quantity.\n\nastropy.units Quantity example\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe following example shows how to restrict the ``radius`` property to\nbe an `astropy.units `__ quantity in\nunits of length:\n\n.. code:: python\n\n from astropy import units as u\n\n class Sphere(object):\n radius = NumericalProperty('radius', convertible_to=u.m)\n\nwill then behave as follows:\n\n.. code:: python\n\n >>> s = Sphere()\n >>> s.radius = 3. * u.m\n >>> s.radius = 4. * u.cm\n >>> s.radius = 4. * u.s\n ...\n ValueError: radius should be in units convertible to m\n\npint Quantity example\n~~~~~~~~~~~~~~~~~~~~~\n\nThe following example shows how to restrict the ``radius`` property to\nbe a `pint `__ quantity in units of\nlength:\n\n.. code:: python\n\n from pint import UnitRegistry\n ureg = UnitRegistry()\n\n class Sphere(object):\n radius = NumericalProperty('radius', convertible_to=ureg.m)\n\nwill then behave as follows:\n\n.. code:: python\n\n >>> s = Sphere()\n >>> s.radius = 3. * ureg.m\n >>> s.radius = 4. * ureg.cm\n >>> s.radius = 4. * ureg.s\n ...\n ValueError: radius should be in units convertible to meter\n\nquantities Quantity example\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nFinally, the following example shows how to restrict the ``radius``\nproperty to be a `quantities `__\nquantity in units of length:\n\n.. code:: python\n\n import quantities as pq\n\n class Sphere(object):\n radius = NumericalProperty('radius', convertible_to=pq.m)\n\nwill then behave as follows:\n\n.. code:: python\n\n >>> s = Sphere()\n >>> s.radius = 3. * pq.m\n >>> s.radius = 4. * pq.cm\n >>> s.radius = 4. * pq.s\n ...\n ValueError: radius should be in units convertible to m\n\nPlanned support\n---------------\n\n- Linking of properties (e.g. a property should have the same\n dimensions as another)\n\n.. |Travis Build Status| image:: https://travis-ci.org/astrofrog/numprops.svg?branch=master\n :target: https://travis-ci.org/astrofrog/numprops\n.. |Coverage Status| image:: https://coveralls.io/repos/astrofrog/numprops/badge.svg\n :target: https://coveralls.io/r/astrofrog/numprops",
"description_content_type": null,
"docs_url": null,
"download_url": "UNKNOWN",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/astrofrog/numprops",
"keywords": null,
"license": "BSD",
"maintainer": null,
"maintainer_email": null,
"name": "numprops",
"package_url": "https://pypi.org/project/numprops/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/numprops/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "https://github.com/astrofrog/numprops"
},
"release_url": "https://pypi.org/project/numprops/0.1/",
"requires_dist": null,
"requires_python": null,
"summary": "Numerical properties for Python objects",
"version": "0.1"
},
"last_serial": 1619850,
"releases": {
"0.1": [
{
"comment_text": "",
"digests": {
"md5": "a9fe632feccf62e487dee364846bd664",
"sha256": "ae747a5f00942c013d8a1e069dc498aebc8c7d1da517bd11329d4a84f4360466"
},
"downloads": -1,
"filename": "numprops-0.1.tar.gz",
"has_sig": false,
"md5_digest": "a9fe632feccf62e487dee364846bd664",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8216,
"upload_time": "2015-07-05T08:01:38",
"url": "https://files.pythonhosted.org/packages/6f/7e/2549538e9bf6986a39c042bef51c5ccd0c49f634d1a11635345823c998ea/numprops-0.1.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "a9fe632feccf62e487dee364846bd664",
"sha256": "ae747a5f00942c013d8a1e069dc498aebc8c7d1da517bd11329d4a84f4360466"
},
"downloads": -1,
"filename": "numprops-0.1.tar.gz",
"has_sig": false,
"md5_digest": "a9fe632feccf62e487dee364846bd664",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8216,
"upload_time": "2015-07-05T08:01:38",
"url": "https://files.pythonhosted.org/packages/6f/7e/2549538e9bf6986a39c042bef51c5ccd0c49f634d1a11635345823c998ea/numprops-0.1.tar.gz"
}
]
}