Skip to content

Commit

Permalink
Merge branch 'master' into infer_time
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage authored Dec 31, 2024
2 parents 104b2cd + 74b7086 commit 1480de2
Show file tree
Hide file tree
Showing 53 changed files with 775 additions and 214 deletions.
14 changes: 9 additions & 5 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"]
numpy: [null, "numpy>=1.23,<2.0.0"]
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ MANIFEST
.mypy_cache
pip-wheel-metadata
pint/testsuite/dask-worker-space
venv
.envrc

# WebDAV file system cache files
.DAV/
Expand Down
77 changes: 73 additions & 4 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,15 +1,83 @@
Pint Changelog
==============

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

- Add docs to the functions in ``pint.testing`` (PR #2070)
- Fix round function returning float instead of int (#2081)
- Fix return type of `PlainQuantity.to` (#2088)
- Update constants to CODATA 2022 recommended values. (#2049)
- Fixed issue with `.to_compact` and Magnitudes with uncertainties / Quantities with units (PR #2069, issue #2044)
- `Quantity` now converts `datetime.timedelta` objects to seconds or specified units when
initializing a `Quantity` with a `datetime.timedelta` value.
(PR #1978)

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)
- `Quantity` now converts `datetime.timedelta` objects to seconds or specified units when
initializing a `Quantity` with a `datetime.timedelta` value.
(PR #1978)
- 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 @@ -40,6 +108,7 @@ Pint Changelog
- Add numpy.linalg.norm implementation.
(PR #1251)


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
2 changes: 1 addition & 1 deletion docs/advanced/measurement.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ the `Propagation of uncertainty`_ rules.


.. _`Propagation of uncertainty`: http://en.wikipedia.org/wiki/Propagation_of_uncertainty
.. _`Uncertainties package`: https://uncertainties-python-package.readthedocs.io/en/latest/
.. _`Uncertainties package`: https://uncertainties.readthedocs.io/en/latest/
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/
6 changes: 4 additions & 2 deletions docs/advanced/pitheorem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ Which can be pretty printed using the `Pint` formatter:

>>> from pint import formatter
>>> result = pi_theorem({'V': '[length]/[time]', 'T': '[time]', 'L': '[length]'})
>>> print(formatter(result[0].items()))
T * V / L
>>> numerator = [item for item in result[0].items() if item[1]>0]
>>> denominator = [item for item in result[0].items() if item[1]<0]
>>> print(formatter(numerator, denominator))
V * T / L

You can also apply the Buckingham π theorem associated to a Registry. In this case,
you can use derived dimensions such as speed:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/facets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The default UnitRegistry inherits from all of them.
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

.. automodule:: pint.facets.formatting
.. automodule:: pint.delegates.formatter
:members:
:exclude-members: Quantity, Unit, Measurement, Group, Context, System

Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"sphinx_design",
]


# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

Expand Down
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
1 change: 1 addition & 0 deletions docs/getting/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ License
-------

.. literalinclude:: ../../LICENSE
:language: none

.. _`comprehensive list of physical units, prefixes and constants`: https://github.com/hgrecco/pint/blob/master/pint/default_en.txt
.. _`uncertainties package`: https://pythonhosted.org/uncertainties/
Expand Down
12 changes: 6 additions & 6 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 All @@ -428,7 +428,7 @@ If Babel_ is installed you can translate unit names to any language
.. doctest::

>>> ureg.formatter.format_quantity(accel, locale='fr_FR')
'1,3 mètres/secondes²'
'1,3 mètres par seconde²'

You can also specify the format locale at the registry level either at creation:

Expand All @@ -446,14 +446,14 @@ 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/secondes²'
'1,3 mètres par seconde²'
>>> "%s" % accel
'1,3 mètres/secondes²'
'1,3 mètres par seconde²'
>>> "{}".format(accel)
'1,3 mètres/secondes²'
'1,3 mètres par seconde²'

If you want to customize string formatting, take a look at :ref:`formatting`.

Expand Down
2 changes: 1 addition & 1 deletion docs/user/angular_frequency.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


Angles and Angular Frequency
=================
=============================

Angles
------
Expand Down
2 changes: 1 addition & 1 deletion docs/user/defining-quantities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ For example, the units of
.. doctest::

>>> Q_('3 l / 100 km')
<Quantity(0.03, 'kilometer * liter')>
<Quantity(0.03, 'liter * kilometer')>

may be unexpected at first but, are a consequence of applying this rule. Use
brackets to get the expected result:
Expand Down
8 changes: 5 additions & 3 deletions docs/user/formatting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ formats:
... def format_unit_simple(unit, registry, **options):
... return " * ".join(f"{u} ** {p}" for u, p in unit.items())
>>> f"{q:Z}"
'2.3e-06 meter ** 3 * second ** -2 * kilogram ** -1'
'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 All @@ -111,10 +112,11 @@ following methods: `format_magnitude`, `format_unit`, `format_quantity`, `format
...
... default_format = ""
...
... def format_unit(self, unit, uspec: str = "", **babel_kwds) -> str:
... def format_unit(self, unit, uspec, sort_func, **babel_kwds) -> str:
... return "ups!"
...
>>> ureg.formatter = MyFormatter()
>>> ureg.formatter._registry = ureg
>>> str(q)
'2.3e-06 ups!'

Expand Down
Loading

0 comments on commit 1480de2

Please sign in to comment.