Skip to content

Commit

Permalink
Merge branch 'master' into implement_broadcast_arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
djpugh authored Nov 18, 2024
2 parents 87c18c7 + 861953e commit 4627654
Show file tree
Hide file tree
Showing 36 changed files with 452 additions and 122 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
numpy: [null, "numpy>=1.23,<2.0.0", "numpy>=2.0.0rc1"]
uncertainties: [null, "uncertainties==3.1.6", "uncertainties>=3.1.6,<4.0.0"]
extras: [null]
include:
- python-version: "3.10" # Minimal versions
numpy: "numpy"
extras: matplotlib==2.2.5
numpy: "numpy>=1.23,<2.0.0"
extras: matplotlib==3.5.3
- python-version: "3.10"
numpy: "numpy"
uncertainties: "uncertainties"
extras: "sparse xarray netCDF4 dask[complete]==2023.4.0 graphviz babel==2.8 mip>=1.13"
extras: "sparse xarray netCDF4 dask[complete]==2024.5.1 graphviz babel==2.8 mip>=1.13"
- python-version: "3.10"
numpy: "numpy==1.26.1"
uncertainties: null
extras: "babel==2.15 matplotlib==3.9.0"
runs-on: ubuntu-latest

env:
Expand Down
58 changes: 54 additions & 4 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,26 +1,77 @@
Pint Changelog
==============

0.24 (unreleased)
-----------------
0.25.0 (unreleased)
-------------------

- Implement numpy broadcast_array (Related to issue #981)


0.24.4 (2024-11-07)
-------------------

- add error for prefixed non multi units (#1998)
- build: typing_extensions version
- build: switch from appdirs to platformdirs
- fix GenericPlainRegistry getattr type (#2045)
- Replace references to the deprecated `UnitRegistry.default_format` (#2058)
- fix: upgrade to flexparser>=0.4, exceptions are no longer dataclasses.
(required for Python 3.13)


0.24.2 (2024-07-28)
-------------------

- Fix the default behaviour for pint-convert (cli) for importing uncertainties package (PR #2032, Issue #2016)
- Added mu and mc as alternatives for SI micro prefix
- Added ℓ as alternative for liter
- Support permille units and `‰` symbol (PR #2033, Issue #1963)
- Switch from appdirs to platformdirs.
- Fixes issues related to GenericPlainRegistry.__getattr__ type (PR #2038, Issues #1946 and #1804)
- Removed deprecated references in documentation and tests (PR #2058, Issue #2057)


0.24.1 (2024-06-24)
-----------------

- Fix custom formatter needing the registry object. (PR #2011)
- Support python 3.9 following difficulties installing with NumPy 2. (PR #2019)
- Fix default formatting of dimensionless unit issue. (PR #2012)
- Fix bug preventing custom formatters with modifiers working. (PR #2021)


0.24 (2024-06-07)
-----------------

- Fix detection of invalid conversion between offset and delta units. (PR #1905)
- Added dBW, decibel Watts, which is used in RF high power applications
- NumPy 2.0 support
(PR #1985, #1971)
- Implement numpy roll (Related to issue #981)
- Implement numpy correlate
(PR #1990)
- Add `dim_sort` function to _formatter_helpers.
- Add `dim_order` and `default_sort_func` properties to FullFormatter.
(PR #1926, fixes Issue #1841)
- Minimum version requirement added for typing_extensions>=4.0.0.
(PR #1996)
- Documented packages using pint.
(PR #1960)
- Fixed bug causing operations between arrays of quantity scalars and quantity holding
array resulting in incorrect units.
(PR #1677)
- Fix LaTeX siuntix formatting when using non_int_type=decimal.Decimal.
(PR #1977)
- Added refractive index units.
(PR #1816)
- Fix converting to offset units of higher dimension e.g. gauge pressure
(PR #1949)
- Fix unhandled TypeError when auto_reduce_dimensions=True and non_int_type=Decimal
(PR #1853)
- Creating prefixed offset units now raises an error.
(PR #1998)
- Improved error message in `get_dimensionality()` when non existent units are passed.
(PR #1874, Issue #1716)


0.23 (2023-12-08)
Expand Down Expand Up @@ -50,8 +101,7 @@ Pint Changelog
(PR #1819)
- Add numpy.linalg.norm implementation.
(PR #1251)
- Improved error message in `get_dimensionality()` when non existent units are passed.
(PR #1874, Issue #1716)


0.22 (2023-05-25)
-----------------
Expand Down
1 change: 0 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
:alt: Latest Version

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
:target: https://github.com/python/black
:target: https://github.com/astral-sh/ruff
:alt: Ruff

Expand Down
8 changes: 7 additions & 1 deletion docs/_static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ pre, code {

.sd-card .sd-card-header {
border: none;
color: #150458 !important;
color: #150458;
font-size: var(--pst-font-size-h5);
font-weight: bold;
padding: 2.5rem 0rem 0.5rem 0rem;
}

html[data-theme=dark] {
.sd-card .sd-card-header {
color: #FFF;
}
}
13 changes: 13 additions & 0 deletions docs/advanced/currencies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,16 @@ currency on its own dimension, and then implement transformations::
More sophisticated formulas, e.g. dealing with flat fees and thresholds, can be
implemented with arbitrary python code by programmatically defining a context (see
:ref:`contexts`).

Currency Symbols
----------------

Many common currency symbols are not supported by the pint parser. A preprocessor can be used as a workaround:

.. doctest::

>>> import pint
>>> ureg = pint.UnitRegistry(preprocessors = [lambda s: s.replace("", "EUR")])
>>> ureg.define("euro = [currency] = € = EUR")
>>> print(ureg.Quantity("1 €"))
1 euro
4 changes: 2 additions & 2 deletions docs/advanced/performance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ If you want to use the default cache folder provided by the OS, use **:auto:**
>>> import pint
>>> ureg = pint.UnitRegistry(cache_folder=":auto:") # doctest: +SKIP
Pint use an included version of appdirs_ to obtain the correct folder,
Pint use an external dependency of platformdirs_ to obtain the correct folder,
for example in macOS is `/Users/<username>/Library/Caches/pint`

In any case, you can check the location of the cache folder.
Expand All @@ -146,5 +146,5 @@ In any case, you can check the location of the cache folder.


.. _`brentq method`: http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.brentq.html
.. _appdirs: https://pypi.org/project/appdirs/
.. _platformdirs: https://pypi.org/project/platformdirs
.. _flexcache: https://github.com/hgrecco/flexcache/
27 changes: 15 additions & 12 deletions docs/dev/pint-convert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,39 @@ With the `uncertainties` package, the experimental uncertainty in the physical
constants is considered, and the result is given in compact notation, with the
uncertainty in the last figures in parentheses:

The uncertainty can be enabled with `-U` (by default it is not enabled):

.. code-block:: console
$ pint-convert -p 20 -U Eh eV
1 hartree = 27.211386245988(52) eV
.. code-block:: console
$ pint-convert Eh eV
$ pint-convert -U Eh eV
1 hartree = 27.21138624599(5) eV
The precision is limited by both the maximum number of significant digits (`-p`)
and the maximum number of uncertainty digits (`-u`, 2 by default)::

$ pint-convert -p 20 Eh eV
$ pint-convert -U -p 20 Eh eV
1 hartree = 27.211386245988(52) eV

$ pint-convert -p 20 -u 4 Eh eV
$ pint-convert -U -p 20 -u 4 Eh eV
1 hartree = 27.21138624598847(5207) eV

The uncertainty can be disabled with `-U`):

.. code-block:: console
$ pint-convert -p 20 -U Eh eV
1 hartree = 27.211386245988471444 eV
Correlations between experimental constants are also known, and taken into
account. Use `-C` to disable it:
account if uncertainties `-U` is enabled. Use `-C` to disable it:

.. code-block:: console
$ pint-convert --sys atomic m_p
1 proton_mass = 1836.15267344 m_e
$ pint-convert -U --sys atomic m_p
1 proton_mass = 1836.15267344(11) m_e
$ pint-convert --sys atomic -C m_p
$ pint-convert -U --sys atomic -C m_p
1 proton_mass = 1836.15267344(79) m_e
Again, note that results may differ slightly, usually in the last figure, from
Expand Down
13 changes: 13 additions & 0 deletions docs/ecosystem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,18 @@ Here is a list of known projects, packages and integrations using pint.
Pint integrations:
------------------

- `ucumvert <https://github.com/dalito/ucumvert>`_ `UCUM <https://ucum.org/>`_ (Unified Code for Units of Measure) integration
- `pint-pandas <https://github.com/hgrecco/pint-pandas>`_ Pandas integration
- `pint-xarray <https://github.com/xarray-contrib/pint-xarray>`_ Xarray integration


Packages using pint:
------------------

- `fluids <https://github.com/CalebBell/fluids>`_ Practical fluid dynamics calculations
- `ht <https://github.com/CalebBell/ht/>`_ Practical heat transfer calculations
- `chemicals <https://github.com/CalebBell/chemicals/>`_ Chemical property calculations and lookups
- `thermo <https://github.com/CalebBell/thermo/>`_ Thermodynamic equilibrium calculations
- `Taurus <https://taurus-scada.org/>`_ Control system UI creation
- `InstrumentKit <https://github.com/instrumentkit/InstrumentKit>`_ Interacting with laboratory equipment over various buses.
- `NEMO <https://github.com/bje-/NEMO/>`_ Electricity production cost model
4 changes: 2 additions & 2 deletions docs/getting/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ Additionally, you can specify a default format specification:
>>> accel = 1.3 * ureg.parse_units('meter/second**2')
>>> 'The acceleration is {}'.format(accel)
'The acceleration is 1.3 meter / second ** 2'
>>> ureg.default_format = 'P'
>>> ureg.formatter.default_format = 'P'
>>> 'The acceleration is {}'.format(accel)
'The acceleration is 1.3 meter/second²'

Expand Down Expand Up @@ -446,7 +446,7 @@ and by doing that, string formatting is now localized:

.. doctest::

>>> ureg.default_format = 'P'
>>> ureg.formatter.default_format = 'P'
>>> accel = 1.3 * ureg.parse_units('meter/second**2')
>>> str(accel)
'1,3 mètres par seconde²'
Expand Down
3 changes: 2 additions & 1 deletion docs/user/formatting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ formats:
'2.3e-06 kilogram ** -1 * meter ** 3 * second ** -2'

where ``unit`` is a :py:class:`dict` subclass containing the unit names and
their exponents.
their exponents, ``registry`` is the current instance of :py:class:``UnitRegistry`` and
``options`` is not yet implemented.

You can choose to replace the complete formatter. Briefly, the formatter if an object with the
following methods: `format_magnitude`, `format_unit`, `format_quantity`, `format_uncertainty`,
Expand Down
6 changes: 3 additions & 3 deletions docs/user/log_units.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ will not work:
.. doctest::

>>> -161.0 * ureg('dBm/Hz') == (-161.0 * ureg.dBm / ureg.Hz)
False
np.False_

But this will:

.. doctest::

>>> ureg('-161.0 dBm/Hz') == (-161.0 * ureg.dBm / ureg.Hz)
True
np.True_
>>> Q_(-161.0, 'dBm') / ureg.Hz == (-161.0 * ureg.dBm / ureg.Hz)
True
np.True_

To begin using this feature while avoiding problems, define logarithmic units
as single-unit quantities and convert them to their base units as quickly as
Expand Down
2 changes: 1 addition & 1 deletion docs/user/nonmult.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For example, to convert from celsius to fahrenheit:

>>> from pint import UnitRegistry
>>> ureg = UnitRegistry()
>>> ureg.default_format = '.3f'
>>> ureg.formatter.default_format = '.3f'
>>> Q_ = ureg.Quantity
>>> home = Q_(25.4, ureg.degC)
>>> print(home.to('degF'))
Expand Down
13 changes: 11 additions & 2 deletions pint/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
from typing import (
Any,
NoReturn,
TypeAlias, # noqa
)

if sys.version_info >= (3, 10):
from typing import TypeAlias # noqa
else:
from typing_extensions import TypeAlias # noqa

if sys.version_info >= (3, 11):
from typing import Self # noqa
else:
Expand Down Expand Up @@ -71,7 +75,8 @@ class BehaviorChangeWarning(UserWarning):

try:
from uncertainties import UFloat, ufloat
from uncertainties import unumpy as unp

unp = None

HAS_UNCERTAINTIES = True
except ImportError:
Expand All @@ -88,6 +93,8 @@ class BehaviorChangeWarning(UserWarning):
HAS_NUMPY = True
NUMPY_VER = np.__version__
if HAS_UNCERTAINTIES:
from uncertainties import unumpy as unp

NUMERIC_TYPES = (Number, Decimal, ndarray, np.number, UFloat)
else:
NUMERIC_TYPES = (Number, Decimal, ndarray, np.number)
Expand Down Expand Up @@ -233,6 +240,8 @@ def _to_magnitude(value, force_ndarray=False, force_ndarray_like=False):
"xarray.core.variable.Variable",
"pandas.core.series.Series",
"pandas.core.frame.DataFrame",
"pandas.Series",
"pandas.DataFrame",
"xarray.core.dataarray.DataArray",
)

Expand Down
6 changes: 4 additions & 2 deletions pint/default_en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pico- = 1e-12 = p-
nano- = 1e-9 = n-
# The micro (U+00B5) and Greek mu (U+03BC) are both valid prefixes,
# and they often use the same glyph.
micro- = 1e-6 = µ- = μ- = u-
micro- = 1e-6 = µ- = μ- = u- = mu- = mc-
milli- = 1e-3 = m-
centi- = 1e-2 = c-
deci- = 1e-1 = d-
Expand Down Expand Up @@ -150,6 +150,7 @@ byte = 8 * bit = B = octet

# Ratios
percent = 0.01 = %
permille = 0.001 = ‰
ppm = 1e-6

# Length
Expand Down Expand Up @@ -221,7 +222,7 @@ hectare = 100 * are = ha

# Volume
[volume] = [length] ** 3
liter = decimeter ** 3 = l = L = litre
liter = decimeter ** 3 = l = L = ℓ = litre
cubic_centimeter = centimeter ** 3 = cc
lambda = microliter = λ
stere = meter ** 3
Expand Down Expand Up @@ -504,6 +505,7 @@ refractive_index_unit = [] = RIU

# Logaritmic Units of dimensionless quantity: [ https://en.wikipedia.org/wiki/Level_(logarithmic_quantity) ]

decibelwatt = watt; logbase: 10; logfactor: 10 = dBW
decibelmilliwatt = 1e-3 watt; logbase: 10; logfactor: 10 = dBm
decibelmicrowatt = 1e-6 watt; logbase: 10; logfactor: 10 = dBu

Expand Down
Loading

0 comments on commit 4627654

Please sign in to comment.