Skip to content

Commit

Permalink
use application reg in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage committed Feb 2, 2024
1 parent 29a139f commit 8671676
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/advanced/performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ A better way to use magnitudes is to use pint's wraps decorator (See :ref:`wrapp

In [1]: import pint

In [2]: ureg = pint.UnitRegistry()
In [2]: ureg = pint.get_application_registry()

In [3]: import numpy as np

Expand Down
4 changes: 2 additions & 2 deletions docs/advanced/serialization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The easiest way to do this is by converting the quantity to a string:
.. doctest::

>>> import pint
>>> ureg = pint.UnitRegistry()
>>> ureg = pint.get_application_registry()
>>> duration = 24.2 * ureg.years
>>> duration
<Quantity(24.2, 'year')>
Expand All @@ -28,7 +28,7 @@ to recover it in another process/machine, you just:
.. doctest::

>>> import pint
>>> ureg = pint.UnitRegistry()
>>> ureg = pint.get_application_registry()
>>> duration = ureg('24.2 year')
>>> print(duration)
24.2 year
Expand Down
2 changes: 1 addition & 1 deletion docs/getting/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ It is extremely easy and natural to use:
.. code-block:: python
>>> import pint
>>> ureg = pint.UnitRegistry()
>>> ureg = pint.get_application_registry()
>>> 3 * ureg.meter + 4 * ureg.cm
<Quantity(3.04, 'meter')>
Expand Down
8 changes: 4 additions & 4 deletions docs/user/contexts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ raise an error if you do this directly:
.. doctest::

>>> import pint
>>> ureg = pint.UnitRegistry()
>>> ureg = pint.get_application_registry()
>>> q = 500 * ureg.nm
>>> q.to('Hz')
Traceback (most recent call last):
Expand Down Expand Up @@ -197,7 +197,7 @@ functions. For example:

.. doctest::

>>> ureg = pint.UnitRegistry()
>>> ureg = pint.get_application_registry()
>>> c = pint.Context('ab')
>>> c.add_transformation('[length]', '[time]',
... lambda ureg, x: x / ureg.speed_of_light)
Expand Down Expand Up @@ -258,7 +258,7 @@ Programmatically:

.. code-block:: python
>>> ureg = pint.UnitRegistry()
>>> ureg = pint.get_application_registry()
>>> q = ureg.Quantity("1 BTU")
>>> q.to("J")
1055.056 joule
Expand All @@ -278,7 +278,7 @@ Or with a definitions file::

.. code-block:: python
>>> ureg = pint.UnitRegistry()
>>> ureg = pint.get_application_registry()
>>> ureg.load_definitions("somefile.txt")
>>> q = ureg.Quantity("1 BTU")
>>> q.to("J")
Expand Down
4 changes: 2 additions & 2 deletions docs/user/formatting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ In case the format is omitted, the corresponding value in the object's

.. ipython::

In [1]: ureg = pint.UnitRegistry()
In [1]: ureg = pint.get_application_registry()
...: ureg.default_format = "~P"

In [2]: u = ureg.Unit("m ** 2 / s ** 2")
Expand Down Expand Up @@ -71,7 +71,7 @@ Let's look at some examples:

.. ipython:: python
ureg = pint.UnitRegistry()
ureg = pint.get_application_registry()
u = ureg.kg * ureg.m / ureg.s ** 2
f"{u:P}" # using the pretty format
Expand Down
2 changes: 1 addition & 1 deletion docs/user/numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"# Import Pint\n",
"import pint\n",
"\n",
"ureg = pint.UnitRegistry()\n",
"ureg = pint.get_application_registry()\n",
"Q_ = ureg.Quantity\n",
"\n",
"# Silence NEP 18 warning\n",
Expand Down
10 changes: 5 additions & 5 deletions docs/user/plotting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ a **UnitRegistry**:
.. testsetup:: *

import pint
ureg = pint.UnitRegistry()
ureg = pint.get_application_registry()

.. doctest::

>>> import pint
>>> ureg = pint.UnitRegistry()
>>> ureg = pint.get_application_registry()
>>> ureg.setup_matplotlib()

This support can also be disabled with:
Expand All @@ -36,7 +36,7 @@ This allows plotting quantities with different units:
import numpy as np
import pint

ureg = pint.UnitRegistry()
ureg = pint.get_application_registry()
ureg.setup_matplotlib(True)

y = np.linspace(0, 30) * ureg.miles
Expand All @@ -56,7 +56,7 @@ This also allows controlling the actual plotting units for the x and y axes:
import numpy as np
import pint

ureg = pint.UnitRegistry()
ureg = pint.get_application_registry()
ureg.setup_matplotlib(True)

y = np.linspace(0, 30) * ureg.miles
Expand All @@ -79,7 +79,7 @@ Users have the possibility to change the format of the units on the plot:
import numpy as np
import pint

ureg = pint.UnitRegistry()
ureg = pint.get_application_registry()
ureg.setup_matplotlib(True)

ureg.mpl_formatter = "{:~P}"
Expand Down

0 comments on commit 8671676

Please sign in to comment.