Improved docs for testing
This commit is contained in:
42
.travis.yml
42
.travis.yml
@@ -68,63 +68,63 @@ after_success:
|
|||||||
matrix:
|
matrix:
|
||||||
exclude:
|
exclude:
|
||||||
# Do not edit after this line
|
# Do not edit after this line
|
||||||
|
- python: "3.5"
|
||||||
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
|
||||||
- python: "3.5"
|
- python: "3.5"
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.8.2
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.8.2
|
||||||
- python: "3.5"
|
- python: "3.5"
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
|
||||||
- python: "3.5"
|
- python: "3.5"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
|
||||||
- python: "3.5"
|
- python: "3.5"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.8.2
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.8.2
|
||||||
- python: "3.5"
|
- python: "3.5"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
|
||||||
- python: "3.5"
|
- python: "3.4"
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
|
||||||
- python: "3.4"
|
- python: "3.4"
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
|
||||||
- python: "3.4"
|
- python: "3.4"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
|
||||||
- python: "3.4"
|
- python: "3.4"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
|
||||||
- python: "3.4"
|
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
|
|
||||||
- python: "3.3"
|
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
|
|
||||||
- python: "3.3"
|
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
|
|
||||||
- python: "3.3"
|
- python: "3.3"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
|
||||||
- python: "3.3"
|
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
|
|
||||||
- python: "3.3"
|
- python: "3.3"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
|
||||||
|
- python: "3.3"
|
||||||
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
|
||||||
|
- python: "3.3"
|
||||||
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
|
||||||
- python: "3.3"
|
- python: "3.3"
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
|
||||||
- python: "3.2"
|
- python: "3.3"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
|
||||||
- python: "3.2"
|
- python: "3.2"
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
|
||||||
- python: "3.2"
|
- python: "3.2"
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.8.2
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.8.2
|
||||||
- python: "3.2"
|
- python: "3.2"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
|
||||||
- python: "3.2"
|
- python: "3.2"
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
|
||||||
|
- python: "3.2"
|
||||||
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
|
||||||
- python: "3.2"
|
- python: "3.2"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.7.1
|
||||||
- python: "3.2"
|
- python: "3.2"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.8.2
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.8.2
|
||||||
- python: "3.2"
|
- python: "3.2"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.6.2
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.6.2
|
||||||
- python: "3.2"
|
- python: "3.2"
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
|
||||||
- python: "3.2"
|
- python: "3.2"
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.7.1
|
|
||||||
- python: "2.6"
|
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
|
||||||
- python: "2.6"
|
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
|
|
||||||
- python: "2.6"
|
- python: "2.6"
|
||||||
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.9.3
|
||||||
|
- python: "2.6"
|
||||||
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.10.4
|
||||||
- python: "2.6"
|
- python: "2.6"
|
||||||
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
|
env: UNCERTAINTIES="Y" NUMPY_VERSION=1.9.3
|
||||||
|
- python: "2.6"
|
||||||
|
env: UNCERTAINTIES="N" NUMPY_VERSION=1.10.4
|
||||||
|
|||||||
@@ -50,7 +50,13 @@ author = 'Hernan E. Grecco'
|
|||||||
# |version| and |release|, also used in various other places throughout the
|
# |version| and |release|, also used in various other places throughout the
|
||||||
# built documents.
|
# built documents.
|
||||||
|
|
||||||
version = pkg_resources.get_distribution(project).version
|
try: # pragma: no cover
|
||||||
|
version = pkg_resources.get_distribution(project).version
|
||||||
|
except: # pragma: no cover
|
||||||
|
# we seem to have a local copy not installed without setuptools
|
||||||
|
# so the reported version will be unknown
|
||||||
|
version = "unknown"
|
||||||
|
|
||||||
release = version
|
release = version
|
||||||
this_year = datetime.date.today().year
|
this_year = datetime.date.today().year
|
||||||
copyright = '%s, %s' % (this_year, author)
|
copyright = '%s, %s' % (this_year, author)
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ mass.
|
|||||||
.. doctest::
|
.. doctest::
|
||||||
|
|
||||||
>>> substance = 95 * ureg('g')
|
>>> substance = 95 * ureg('g')
|
||||||
>>> moles = substance.to('moles', 'chemistry', mw = 5 * ureg('g/mol'))
|
>>> substance.to('moles', 'chemistry', mw = 5 * ureg('g/mol'))
|
||||||
<Quantity(19.0, 'mole')>
|
<Quantity(19.0, 'mole')>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ User Guide
|
|||||||
measurement
|
measurement
|
||||||
defining
|
defining
|
||||||
performance
|
performance
|
||||||
|
systems
|
||||||
|
|
||||||
|
|
||||||
More information
|
More information
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ If you want to add a quantity with absolute unit to one with offset unit, like h
|
|||||||
>>> Q_(10., ureg.degC) + heating_rate * Q_(30, ureg.min)
|
>>> Q_(10., ureg.degC) + heating_rate * Q_(30, ureg.min)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
pint.unit.OffsetUnitCalculusError: Ambiguous operation with offset unit (degC, kelvin).
|
pint.errors.OffsetUnitCalculusError: Ambiguous operation with offset unit (degC, kelvin).
|
||||||
|
|
||||||
you have to avoid the ambiguity by either converting the offset unit to the
|
you have to avoid the ambiguity by either converting the offset unit to the
|
||||||
absolute unit before addition
|
absolute unit before addition
|
||||||
@@ -157,7 +157,7 @@ You can change the behaviour at any time:
|
|||||||
>>> 1/T
|
>>> 1/T
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
pint.unit.OffsetUnitCalculusError: Ambiguous operation with offset unit (degC).
|
pint.errors.OffsetUnitCalculusError: Ambiguous operation with offset unit (degC).
|
||||||
|
|
||||||
The parser knows about *delta* units and uses them when a temperature unit
|
The parser knows about *delta* units and uses them when a temperature unit
|
||||||
is found in a multiplicative context. For example, here:
|
is found in a multiplicative context. For example, here:
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ All usual Pint methods can be used with this quantity. For example:
|
|||||||
>>> legs1.to('joule')
|
>>> legs1.to('joule')
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
DimensionalityError: Cannot convert from 'meter' ([length]) to 'joule' ([length] ** 2 * [mass] / [time] ** 2)
|
pint.errors.DimensionalityError: Cannot convert from 'meter' ([length]) to 'joule' ([length] ** 2 * [mass] / [time] ** 2)
|
||||||
|
|
||||||
NumPy functions are supported by Pint. For example if we define:
|
NumPy functions are supported by Pint. For example if we define:
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ results in an error:
|
|||||||
>>> np.arccos(legs2)
|
>>> np.arccos(legs2)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
DimensionalityError: Cannot convert from 'centimeter' ([length]) to 'dimensionless' (dimensionless)
|
pint.errors.DimensionalityError: Cannot convert from 'centimeter' ([length]) to 'dimensionless' (dimensionless)
|
||||||
|
|
||||||
|
|
||||||
Support
|
Support
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
.. systems_:
|
.. _systems:
|
||||||
|
|
||||||
Different Unit Systems (and default units)
|
Different Unit Systems (and default units)
|
||||||
==========================================
|
==========================================
|
||||||
@@ -16,11 +16,6 @@ This has an effect in the base units. For example:
|
|||||||
>>> q.to_base_units()
|
>>> q.to_base_units()
|
||||||
<Quantity(1.0, 'meter / second')>
|
<Quantity(1.0, 'meter / second')>
|
||||||
|
|
||||||
We can take a look for the available systems
|
|
||||||
|
|
||||||
>>> ureg.systems
|
|
||||||
frozenset({'US', 'mks', 'imperial', 'cgs'})
|
|
||||||
|
|
||||||
But if you change to cgs:
|
But if you change to cgs:
|
||||||
|
|
||||||
>>> ureg.default_system = 'cgs'
|
>>> ureg.default_system = 'cgs'
|
||||||
@@ -60,7 +55,7 @@ You can check which unit systems are available:
|
|||||||
Or which units are available within a particular system:
|
Or which units are available within a particular system:
|
||||||
|
|
||||||
>>> dir(ureg.sys.imperial)
|
>>> dir(ureg.sys.imperial)
|
||||||
['acre', 'acre_foot', 'board_foot', 'cable', 'chain', 'fathom', 'foot', 'furlong', 'imperial_bushel', 'imperial_cup', 'imperial_fluid_ounce', 'imperial_gallon', 'imperial_gill', 'imperial_pint', 'imperial_quart', 'inch', 'league', 'mile', 'nautical_mile', 'perch', 'pica', 'point', 'rood', 'square_foot', 'square_yard', 'thou', 'yard']
|
['acre', 'acre_foot', 'board_foot', 'cable', 'chain', 'fathom', 'foot', 'furlong', 'imperial_barrel', 'imperial_bushel', 'imperial_cup', 'imperial_fluid_ounce', 'imperial_gallon', 'imperial_gill', 'imperial_pint', 'imperial_quart', 'inch', 'league', 'mile', 'nautical_mile', 'perch', 'pica', 'point', 'rood', 'square_foot', 'square_yard', 'thou', 'yard']
|
||||||
|
|
||||||
Notice that this give you the opportunity to choose within units with colliding names:
|
Notice that this give you the opportunity to choose within units with colliding names:
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ and handled. You start by creating your registry::
|
|||||||
ureg = UnitRegistry()
|
ureg = UnitRegistry()
|
||||||
Q_ = ureg.Quantity
|
Q_ = ureg.Quantity
|
||||||
|
|
||||||
|
|
||||||
If no parameter is given to the constructor, the unit registry is populated
|
If no parameter is given to the constructor, the unit registry is populated
|
||||||
with the default list of units and prefixes.
|
with the default list of units and prefixes.
|
||||||
You can now simply use the registry in the following way:
|
You can now simply use the registry in the following way:
|
||||||
@@ -88,7 +89,7 @@ If you ask Pint to perform an invalid conversion:
|
|||||||
>>> speed.to(ureg.joule)
|
>>> speed.to(ureg.joule)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
pint.pint.DimensionalityError: Cannot convert from 'inch / minute' (length / time) to 'joule' (length ** 2 * mass / time ** 2)
|
pint.errors.DimensionalityError: Cannot convert from 'inch / minute' ([length] / [time]) to 'joule' ([length] ** 2 * [mass] / [time] ** 2)
|
||||||
|
|
||||||
|
|
||||||
There are also methods 'to_base_units' and 'ito_base_units' which automatically
|
There are also methods 'to_base_units' and 'ito_base_units' which automatically
|
||||||
|
|||||||
@@ -63,15 +63,18 @@ Pint provides a more convenient way to do this:
|
|||||||
|
|
||||||
>>> mypp = ureg.wraps(ureg.second, ureg.meter)(pendulum_period)
|
>>> mypp = ureg.wraps(ureg.second, ureg.meter)(pendulum_period)
|
||||||
|
|
||||||
To understand the syntax, consider the usage in the decorator format:
|
Or in the decorator format:
|
||||||
|
|
||||||
.. doctest::
|
.. doctest::
|
||||||
|
|
||||||
>>> @ureg.wraps(ureg.second, ureg.meter)
|
>>> @ureg.wraps(ureg.second, ureg.meter)
|
||||||
... def mypp(length):
|
... def mypp(length):
|
||||||
... return pendulum_period(length)
|
... return pendulum_period(length)
|
||||||
|
>>> mypp(100 * ureg.centimeter)
|
||||||
|
<Quantity(2.0064092925890407, 'second')>
|
||||||
|
|
||||||
`wraps` takes 3 input arguments::
|
|
||||||
|
`wraps` takes 3 input arguments:
|
||||||
|
|
||||||
- **ret**: the return units.
|
- **ret**: the return units.
|
||||||
Use None to skip conversion.
|
Use None to skip conversion.
|
||||||
@@ -80,8 +83,7 @@ To understand the syntax, consider the usage in the decorator format:
|
|||||||
- **strict**: if `True` all convertible arguments must be a Quantity
|
- **strict**: if `True` all convertible arguments must be a Quantity
|
||||||
and others will raise a ValueError (True by default)
|
and others will raise a ValueError (True by default)
|
||||||
|
|
||||||
>>> mypp(100 * ureg.centimeter)
|
|
||||||
<Quantity(2.0064092925890407, 'second')>
|
|
||||||
|
|
||||||
Strict Mode
|
Strict Mode
|
||||||
-----------
|
-----------
|
||||||
@@ -154,11 +156,11 @@ which can be read as the first argument (`x`) has certain units (we labeled them
|
|||||||
the second argument (`y`) has the same units as the first (`A` again). The return value
|
the second argument (`y`) has the same units as the first (`A` again). The return value
|
||||||
has the unit of `x` squared (`A**2`)
|
has the unit of `x` squared (`A**2`)
|
||||||
|
|
||||||
You can use more than one labels.
|
You can use more than one label:
|
||||||
|
|
||||||
>>> @ureg.wraps('=A**2*B', ('=A', '=A*B', '=B'))
|
>>> @ureg.wraps('=A**2*B', ('=A', '=A*B', '=B'))
|
||||||
... def some_function(x, y, z):
|
... def some_function(x, y, z):
|
||||||
|
... pass
|
||||||
|
|
||||||
|
|
||||||
Ignoring an argument or return value
|
Ignoring an argument or return value
|
||||||
|
|||||||
Reference in New Issue
Block a user