<commit_before>Numerical properties for Python objects
=======================================

[![Travis Build Status](https://travis-ci.org/astrofrog/numprops.svg?branch=master)](https://travis-ci.org/astrofrog/numprops)

About
-----

This simple module defines a descriptor class that can be used to define
numerical properties (scalar and n-dimensional arrays) on classes and provide a
way to validate these:

    from numprops import NumericalProperty

    class Source(object):

        radius = NumericalProperty('radius', domain='strictly-positive')
        position = NumericalProperty('position', shape=(3,))
        
When a property is set, it will be validated:

    >>> s = Source()
    >>> s.radius = 1.
    >>> s.radius = -3
    ...
    ValueError: radius should be strictly positive
    >>> s.position = (1,2,3)
    >>> s.position = 3
    ...
    TypeError: position should be a 1-d sequence
    >>> s.position = (1,2,3,4)
    ...
    ValueError: position has incorrect length (expected 3 but found 4)
    
Planned support
---------------

* Linking of properties (e.g. a property should have the same dimensions as another)
* Validation of physical types (for example using ``astropy.units`` or ``quantities``)
<commit_msg>Specify that example is Python in README<commit_after>Numerical properties for Python objects
=======================================

[![Travis Build Status](https://travis-ci.org/astrofrog/numprops.svg?branch=master)](https://travis-ci.org/astrofrog/numprops)

About
-----

This simple module defines a descriptor class that can be used to define
numerical properties (scalar and n-dimensional arrays) on classes and provide a
way to validate these:

```python
from numprops import NumericalProperty

class Source(object):

    radius = NumericalProperty('radius', domain='strictly-positive')
    position = NumericalProperty('position', shape=(3,))
```
        
When a property is set, it will be validated:

    >>> s = Source()
    >>> s.radius = 1.
    >>> s.radius = -3
    ...
    ValueError: radius should be strictly positive
    >>> s.position = (1,2,3)
    >>> s.position = 3
    ...
    TypeError: position should be a 1-d sequence
    >>> s.position = (1,2,3,4)
    ...
    ValueError: position has incorrect length (expected 3 but found 4)
    
Planned support
---------------

* Linking of properties (e.g. a property should have the same dimensions as another)
* Validation of physical types (for example using ``astropy.units`` or ``quantities``)

{'fraction_non_alphanumeric': 0.15489021956087826, 'fraction_numerical': 0.011177644710578843, 'mean_word_length': 3.3887915936952715, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4680507', 'n_tokens_mistral': 714, 'n_tokens_neox': 685, 'n_words': 243}