Skip to content

Commit

Permalink
Merged updates from pint master
Browse files Browse the repository at this point in the history
  • Loading branch information
varchasgopalaswamy committed Jun 27, 2024
2 parents e006eb6 + f9977ab commit e3fc388
Show file tree
Hide file tree
Showing 133 changed files with 4,581 additions and 4,450 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: "3.11"
python-version: "3.12"

- name: Install dependencies
run: pip install "numpy>=1.21,<2.0.0"
run: pip install "numpy>=1.23,<2.0.0"

- name: Install bench dependencies
run: pip install .[bench]
Expand Down
34 changes: 23 additions & 11 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.9, "3.10", "3.11"]
numpy: [null, "numpy>=1.21,<2.0.0"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
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.9 # Minimal versions
numpy: "numpy"
extras: matplotlib==2.2.5
- python-version: 3.9
- python-version: "3.10" # Minimal versions
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"
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 Expand Up @@ -61,6 +65,14 @@ jobs:
if: ${{ matrix.extras != null }}
run: pip install ${{matrix.extras}}

- name: Install locales
if: ${{ matrix.extras != null }}
run: |
sudo apt-get install language-pack-es language-pack-fr language-pack-ro
sudo localedef -i es_ES -f UTF-8 es_ES
sudo localedef -i fr_FR -f UTF-8 fr_FR
sudo localedef -i ro_RO -f UTF-8 ro_RO
- name: Install dependencies
run: |
sudo apt install -y graphviz
Expand Down Expand Up @@ -92,8 +104,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9, "3.10", "3.11"]
numpy: [ "numpy>=1.21,<2.0.0" ]
python-version: ["3.10", "3.11", "3.12"]
numpy: [ "numpy>=1.23,<2.0.0" ]
runs-on: windows-latest

env:
Expand Down Expand Up @@ -153,8 +165,8 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9, "3.10", "3.11"]
numpy: [null, "numpy>=1.21,<2.0.0" ]
python-version: ["3.10", "3.11", "3.12"]
numpy: [null, "numpy>=1.23,<2.0.0" ]
runs-on: macos-latest

env:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up minimal Python version
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: "3.10"

- name: Get pip cache dir
id: pip-cache
Expand All @@ -30,6 +30,11 @@ jobs:
key: pip-docs
restore-keys: pip-docs

- name: Install locales
run: |
sudo apt-get install language-pack-fr
sudo localedef -i fr_FR -f UTF-8 fr_FR
- name: Install dependencies
run: |
sudo apt install -y pandoc
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
18 changes: 8 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
exclude: '^pint/_vendor'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.240'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
hooks:
- id: ruff
args: ["--fix"]
args: ["--fix", "--show-fixes"]
types_or: [ python, pyi, jupyter ]
- id: ruff-format
types_or: [ python, pyi, jupyter ]
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
rev: 0.7.17
hooks:
- id: mdformat
additional_dependencies:
Expand Down
3 changes: 1 addition & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.9"
python: "3.11"
sphinx:
configuration: docs/conf.py
fail_on_warning: false
Expand All @@ -11,4 +11,3 @@ python:
- requirements: requirements_docs.txt
- method: pip
path: .
system_packages: false
76 changes: 72 additions & 4 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,15 +1,78 @@
Pint Changelog
==============

0.23 (unreleased)
0.25 (unreleased)
-----------------

- Nothing added yet.


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)
- 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)
- Improved error message in `get_dimensionality()` when non existent units are passed.
(PR #1874, Issue #1716)


0.23 (2023-12-08)
-----------------

- Add _get_conversion_factor to registry with cache.
- Homogenize input and ouput of internal regitry functions to
facility typing, subclassing and wrapping.
(_yield_unit_triplets, )
- Generated downstream_status page to track the
state of downstream projects.
- Improve typing annotation.
- Updated to flexparser 0.2.
- Faster wraps
(PR #1862)
- Add codspeed github action.
- Move benchmarks to pytest-benchmarks.
- Support pytest on python 3.12 wrt Fraction formatting change
(#1818)
- Fixed Transformation type protocol.
(PR #1805)
(PR #1805, PR #1832)
- Documented to_preferred and created added an autoautoconvert_to_preferred registry option.
(PR #1803)
- Enable Pint to parse uncertainty numbers.
(See #1611, #1614)
- Optimize matplotlib unit conversion for Quantity arrays
(PR #1819)
- Add numpy.linalg.norm implementation.
(PR #1251)


0.22 (2023-05-25)
Expand Down Expand Up @@ -105,9 +168,15 @@ Pint Changelog
(Issue #1030, #574)
- Added angular frequency documentation page.
- Move ASV benchmarks to dedicated folder. (Issue #1542)
- An ndim attribute has been added to Quantity and DataFrame has been added to upcast
types for pint-pandas compatibility. (#1596)
- Fix a recursion error that would be raised when passing quantities to `cond` and `x`.
(Issue #1510, #1530)
- Update test_non_int tests for pytest.
- Better support for uncertainties (See #1611, #1614)
- Implement `numpy.broadcast_arrays` (#1607)
- An ndim attribute has been added to Quantity and DataFrame has been added to upcast
types for pint-pandas compatibility. (#1596)
types for pint-pandas compatibility. (#1596)
- Fix a recursion error that would be raised when passing quantities to `cond` and `x`.
(Issue #1510, #1530)
- Update test_non_int tests for pytest.
Expand All @@ -116,7 +185,6 @@ types for pint-pandas compatibility. (#1596)
- Better support for pandas and dask.
- Fix masked arrays (with multiple values) incorrectly being passed through
setitem (Issue #1584)

- Add Quantity.to_preferred

0.19.2 (2022-04-23)
Expand Down
9 changes: 7 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
:target: https://pypi.python.org/pypi/pint
:alt: Latest Version

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

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

.. image:: https://readthedocs.org/projects/pint/badge/
:target: https://pint.readthedocs.org/
Expand Down
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
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/changes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../CHANGES
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.
from __future__ import annotations

import datetime
from importlib.metadata import version
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
2 changes: 1 addition & 1 deletion docs/getting/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The getting started guide aims to get you using pint productively as quickly as
Installation
------------

Pint has no dependencies except Python itself. In runs on Python 3.9+.
Pint has no dependencies except Python itself. It runs on Python 3.9+.

.. grid:: 2

Expand Down
14 changes: 8 additions & 6 deletions docs/getting/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ If Babel_ is installed you can translate unit names to any language

.. doctest::

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

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

Expand All @@ -440,20 +440,22 @@ or later:

.. doctest::

>>> ureg.set_fmt_locale('fr_FR')
>>> ureg.formatter.set_locale('fr_FR')

and by doing that, string formatting is now localized:

.. doctest::

>>> ureg.default_format = 'P'
>>> accel = 1.3 * ureg.parse_units('meter/second**2')
>>> str(accel)
'1.3 mètre par seconde²'
'1,3 mètres par seconde²'
>>> "%s" % accel
'1.3 mètre par seconde²'
'1,3 mètres par seconde²'
>>> "{}".format(accel)
'1.3 mètre par seconde²'
'1,3 mètres par seconde²'

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


.. _`default list of units`: https://github.com/hgrecco/pint/blob/master/pint/default_en.txt
Expand Down
Loading

0 comments on commit e3fc388

Please sign in to comment.