Skip to content

gh-67790: Support float-style formatting for Fraction instances #100161

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 34 commits into from
Jan 22, 2023

Conversation

mdickinson
Copy link
Member

@mdickinson mdickinson commented Dec 10, 2022

This PR adds support for float-style formatting for Fraction objects: it supports the "e", "E", "f", "F", "g", "G" and "%" presentation types, and all the various bells and whistles of the formatting mini-language for those presentation types. The behaviour almost exactly matches that of float, but the implementation works with the exact Fraction value and does not do an intermediate conversion to float, and so avoids loss of precision or issues with numbers that are outside the dynamic range of the float type.

Note that the "n" presentation type is not supported. That support could be added later if people have a need for it.

There's one corner-case where the behaviour differs from that of float: for the float type, if explicit alignment is specified with a fill character of '0' and alignment type '=', then thousands separators (if specified) are inserted into the padding string:

>>> format(3.14, '0=11,.2f')
'0,000,003.14'

The exact same effect can be achieved by using the '0' flag:

>>> format(3.14, '011,.2f')
'0,000,003.14'

For Fraction, only the '0' flag has the above behaviour with respect to thousands separators: there's no special-casing of the particular '0=' fill-character/alignment combination. Instead, we treat the fill character '0' just like any other:

>>> format(Fraction('3.14'), '0=11,.2f')
'00000003.14'
>>> format(Fraction('3.14'), '011,.2f')
'0,000,003.14'

The Fraction formatter is also stricter about combining these two things: it's not permitted to use both the '0' flag and explicit alignment, on the basis that we should refuse the temptation to guess in the face of ambiguity. float is less picky:

>>> format(3.14, '0<011,.2f')
'3.140000000'
>>> format(Fraction('3.14'), '0<011,.2f')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mdickinson/Repositories/python/cpython/Lib/fractions.py", line 414, in __format__
    raise ValueError(
ValueError: Invalid format specifier '0<011,.2f' for object of type 'Fraction'; can't use explicit alignment when zero-padding

@netlify
Copy link

netlify bot commented Dec 10, 2022

Deploy Preview for python-cpython-preview canceled.

Name Link
🔨 Latest commit 983726f
🔍 Latest deploy log https://app.netlify.com/sites/python-cpython-preview/deploys/6394be329cefee00083eddef

@mdickinson mdickinson added type-feature A feature request or enhancement 3.12 only security fixes labels Dec 10, 2022
@mdickinson
Copy link
Member Author

Converting to draft while I pacify the doc build.

@mdickinson mdickinson marked this pull request as draft December 10, 2022 16:29
@mdickinson
Copy link
Member Author

Doc build duly pacified; ready for review.

@mdickinson mdickinson marked this pull request as ready for review December 10, 2022 16:58
@mdickinson
Copy link
Member Author

@ericvsmith Would you be willing to review at some point? I'm not looking for detailed line-by-line review (though that would be useful too) so much as big-picture "is this a good idea?" review. In particular, I want to avoid doing anything here that will be hard to undo later if it conflicts with a different approach that we want to take, and that's why I restricted to just implementing the efg% presentation types, where the desired behaviour seems reasonably clear.

@ericvsmith
Copy link
Member

Hi, @mdickinson. Yes, I'll take a look. I'm going to be out of town for a few days, but will review when I get back.

@ericvsmith
Copy link
Member

I forgot to add: yes, I think this is a good idea!

@mdickinson
Copy link
Member Author

@ericvsmith Thanks for reviewing! I'll do another round of self-review, and merge shortly if I don't spot anything blocking.

So I guess as long as we reserve the integer presentation types ('b', 'd', 'o', 'x', 'X'), nothing precludes them being used in the future.

Yes, that was where I was going. Of those, I'm finding it hard to imagine use-cases for anything other than presentation type 'd', though. If I have time before Python 3.12, I'd like to prepare a follow-up PR for presentation type 'd' that:

  • with no other information, behaves identically to str
  • supports fill (with the minimum length applied to the whole output string), alignment, sign manipulation and thousands separators (with the latter applied to both numerator and denominator, as you suggest)
  • does not support zero-fill, because it's not clear exactly what that means
  • makes 'd' the "default" presentation type, so that the presentation type itself can be omitted.
  • as a bonus, supports the '#' "alternate" flag to mean "always express the result as a fraction, even it it's an integer". So e.g., Fraction(3) would be presented as 3/1 rather than just 3. This seems consistent with the uses of '#' in float-style formatting to describe a format that strictly conforms to specifications (keeping a decimal point and trailing zeros) as opposed to being human-friendly (stripping trailing zeros and point).

@mdickinson
Copy link
Member Author

the formatting would be applied to both the numerator and denominator, and weird things happen with the width [...]

I think I'm missing something here. Precision doesn't apply, of course, so it's only the width we need to worry about. I was imagining that this would simply be a minimum width, applied to the formatted fraction as a whole. So for example:

>>> f"{Fraction(22, 7):}"
'22/7'
>>> f"{Fraction(22, 7):10}"  # or '10d' in place of '10'
'      22/7'

I guess that would mean that the slashes wouldn't be nicely aligned in a table of fractions, but I think I could live with that - if anyone needs that alignment they could format the numerator and denominator separately:

>>> f = Fraction(22, 7)
>>> f"{f.numerator:>5}/{f.denominator:<5}"
'   22/7    '

We could try to get fancy and re-use the precision as a minimum width for the denominator:

>>> f"{Fraction(22, 7):10.5}"
'  22/    7'

But this feels like a bit of an abuse, and it also feels as though we're getting into YAGNI territory, and that we're guessing about use-cases without information from actual users.

@mdickinson
Copy link
Member Author

@ericvsmith I've made a proof-of-concept PR (against the branch for this PR) for adding support for the 'd' presentation type at mdickinson#2.

@ericvsmith
Copy link
Member

I think I'm missing something here. Precision doesn't apply, of course, so it's only the width we need to worry about. I was imagining that this would simply be a minimum width, applied to the formatted fraction as a whole.

I think you're right in applying the width to the whole fraction, including the slash. No need to go nutso on this, and as you say, the users could format the numerator and denominator separately. I'll take a look at your branch.

@mdickinson
Copy link
Member Author

@ericvsmith Thanks.

I'll merge this one. There were a few inconsequential style / cosmetic updates since your review, and one bugfix + regression test ("Z" was being accepted as the suppress-negative-zero flag, where only "z" should have been allowed).

@mdickinson mdickinson merged commit 3e09f31 into python:main Jan 22, 2023
scoder added a commit to scoder/quicktions that referenced this pull request Jan 24, 2023
@bszonye
Copy link

bszonye commented Jan 24, 2023

I guess that would mean that the slashes wouldn't be nicely aligned in a table of fractions, but I think I could live with that - if anyone needs that alignment they could format the numerator and denominator separately....

For what it's worth, I spent about a day implementing a tabular format for fractions that aligned the slashes, and I threw the whole thing out because left-aligning the denominators made the fractions too hard to read. Alignment around a radix point works great because it keeps all of the tens, units, tenths, etc. in vertical alignment. The same isn't true for fraction slashes (unless you normalize everything to the same denominator) so it just makes the rows ragged and harder to scan.

bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Mar 21, 2023
https://build.opensuse.org/request/show/1073017
by user dgarcia + dimstar_suse
- Enable python 3.11 build again, now is supported
- Update to 1.14
  - Implement __format__ for Fraction, following python/cpython#100161
  - Implement Fraction.is_integer(), following python/cpython#100488
  - Fraction.limit_denominator() is faster, following
    python/cpython#93730
  - Internal creation of result Fractions is about 10% faster if the
    calculated numerator/denominator pair is already normalised,
    following python/cpython#101780
  - Built using Cython 3.0.0b1.
- 1.13
  - Parsing very long numbers from a fraction string was very slow,
    even slower than fractions.Fraction. The parser is now faster in
    all cases (and still much faster for shorter numbers).
  - Fraction did not implement __int__.
    https://bugs.python.org/issue44547
- 1.12
  - Faster and more spa
mtasaka added a commit to mtasaka/pint that referenced this pull request Jul 17, 2023
python 3.12 supports float-style formatting for Fraction by
python/cpython#100161 .
With this change, when ":n" format specifier is used in format() for
Fraction type, this now raises ValueError instead of previous
TypeError.

To make pytest succeed with python 3.12, make
pint.testing.assert_allclose also rescue ValueError .

Fixes hgrecco#1818 .
jakob-keller added a commit to jakob-keller/peprock that referenced this pull request Aug 6, 2023
mdickinson added a commit that referenced this pull request Dec 16, 2023
PR #100161 added fancy float-style formatting for the Fraction type,
but left us in a state where basic formatting for fractions (alignment,
fill, minimum width, thousands separators) still wasn't supported.

This PR adds that support.

---------

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
PR python#100161 added fancy float-style formatting for the Fraction type,
but left us in a state where basic formatting for fractions (alignment,
fill, minimum width, thousands separators) still wasn't supported.

This PR adds that support.

---------

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
PR python#100161 added fancy float-style formatting for the Fraction type,
but left us in a state where basic formatting for fractions (alignment,
fill, minimum width, thousands separators) still wasn't supported.

This PR adds that support.

---------

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
antonio-perez-altium added a commit to valispace/pint that referenced this pull request Apr 16, 2025
* fix: support pytest on python 3.12 wrt Fraction formatting change

python 3.12 supports float-style formatting for Fraction by
python/cpython#100161 .
With this change, when ":n" format specifier is used in format() for
Fraction type, this now raises ValueError instead of previous
TypeError.

To make pytest succeed with python 3.12, make
pint.testing.assert_allclose also rescue ValueError .

Fixes hgrecco#1818 .

* Fix Transformation typing

* Add PR to changelog

* fix: add np.linalg.norm implementation after merging upstream

* test: rm test as per feedback

* docs: cleanup spurious edits from merge

* Make `babel` a dependency for testbase

Here's hoping this fixes the CI/CD problem with test_1400.

Signed-off-by: Michael Tiemann <72577720+MichaelTiemannOSC@users.noreply.github.com>

* Update .readthedocs.yaml

Removing `system_packages: false` as suggested by @keewis

Signed-off-by: Michael Tiemann <72577720+MichaelTiemannOSC@users.noreply.github.com>

* Fix failing tests

Fix isnan to use unp.isnan as appropriate for both duck_array_type and objects of UFloat types.

Fix a minor typo in pint/facets/__init__.py comment.

In test_issue_1400, use decorators to ensure babel library is loaded when needed.

pyproject.toml: revert change to testbase; we fixed with decorators instead.

Signed-off-by: Michael Tiemann <72577720+MichaelTiemannOSC@users.noreply.github.com>

* add `pint-xarray` to the downstream status page

* fix the nightly badge

* try formatting as a markdown table

* typo in documentation

* Fix typo

* Wraps benchmark (hgrecco#1862)

- Add wrapper benchmark

* Add extra typing annotations

* Pull flexparser.py from https://github.com/hgrecco/flexparser

* Updated PintParser to new flexparser

* Pull flexparser.py from https://github.com/hgrecco/flexparser

* Renamed internal method

* Remove optional argument from _yield_unit_triplets

* Minor typing improvements

* Migrate test_infer_base_unit to use sess_registry, not LazyRegistry

* Migrate test_infer_base_unit to use sess_registry, not LazyRegistry

* Improved testsuite

- Access to internal attributes of registry
  is wrap in a function for future identification.
- More usage of pytest fixtures instead of default registries

* Add a conversion factor cache

* Avoid numpy scalar warnings (hgrecco#1880)

NumPy as of 1.25 deprecated automatically converting any "scalar" with
non-zero number of dimensions to a float value. Therefore, we should
ensure our values have ndim == 0 before passing to math.isnan()

* Replace pkg_resources in test_load (hgrecco#1870)

Replace pkg_resources.resource_filename with importlib.resources.files.
This removes an implicit dependency on setuptools (to which
pkg_resources belongs); furthermore, the entire pkg_resources API is
deprecated.

Regarding the switch from __file__ to __package__, see:
python/importlib_resources#60

* Fix tests for default preferred units (hgrecco#1868)

* TST: fix ureg attribute default_preferred_units and set autoconvert_to_preferred=True in test of autoconvert

* TST: Use class ureg so both regular and _DEFAULT_REGISTRY are tested

* CNF: Add mip install to github ci run to test to_preferred

---------

Co-authored-by: Dana Nadler <nadler@amyris.com>

* Improve wraps performances (hgrecco#1866)

* rename the first positional arg in _trapz to match numpy (hgrecco#1796)

* docs: add changes to docs (hgrecco#1838)

* Add parse_units_as_container to homogeneize input/ouput in registry functions public and private functions

* Updated CHANGES

* Preparing for release 0.23

* Back to development: 0.24

* Fix UnitStrippedWarning for non arrays (hgrecco#1909)

* check magnitude is array
* numpy check

* Add formatter delegate

* to_compact: support uncertainties' Magnitudes , keeping warning

Closing hgrecco#584, hgrecco#1910, hgrecco#1911

* Remove FormattingRegistry/Quantity/Unit in favor of the Formatter delegate

* Moved Locale import to TYPE_CHECKING section

* Work on the formatter delegate

1. split into modules: plain (raw, compact, pretty), latex, html, full
2. added format_magnitude to all Formatters
3. format_ methods have an argument related to babel
   (it must be always there, other architectures lead to multiplication of
   classes or lot of overhead)
4. some test where changed:
   - format_babel was using per (as in meter per seconds) for any format
   - ro was not a valid locale: should be ro_RO

Note: there are still a few circular imports that were fixed in
caveman way in order to move forward.

* Re added imports removed by ruff

* Fixed issues with array sring formatting

* Fixed lack of multiplier in raw format

* Moved babel.Locale to TYPE_CHECKING part

* Changed default format to .16n, equivalent to str or repr for floats

* Change test to use es_ES locale instead of the less common es_AR

* If sorted not selected, make a tuple and only then compare for emptiness so that iterables work

* Make value used in test more clear and direct

* Better reporting in subtest

* Make D the default formatter if spec is empty

* Create function to join magnitude and units that deal with 3 1 / s

* Create and use function to format scalar, use function to join magnitude and units

* Removed unused babel part from formatter

* Migrated test_measurement from subtests to parametrize

* Remove redundant test for measurement

* Improve number formatting

* More comprehensive number formatting

* Removed old formatting code from pint/formatting.py but keeping backwards compatiblity

* Fixed babel test to show that now numbers are localized

* Changed tests to compare localized versions

* Changed some tests to point from ureg.default_format to ureg.formatter.default_format

* Changed formatter code to point from ureg.default_format to ureg.formatter.default_format

* Added class to enable dynamic registration (backwards compatiblity)

* Marked some tests as xfail until behavior is defined

* CI: Install locals when babel is available

* CI: add sudo to install locales

* CI: fixed error in locale name

* CI: generate localedef to avoid utf-8 in locale name

* DOC: Require a more recent version of `sphinx` (hgrecco#1923)

* update sphinx to use at least version 7
* downgrade the min-sphinx version but upgrade `sphinx-book-theme`
* upgrade to python 3.11

* feat: explicitly implement the `dtype` on `numpy` quantities (hgrecco#1922)

* refactor: reorganized formatter and added docs

* refactor: simplify register_unit_format to avoid in function imports and better interplay with registry

* perf: use _get_symbol instead of get_symbol when short formatting (~)

This assumes that the unit has the canonical name, but it was the same
assumption that in pint 0.23

* fix: typing annnotation, V typevar was not defined properly

* doc: updated string formatting documentation

* fix: indentation in CHANGES

* doc: migrated the formatting guide from ipython to doctest

* doc: fixed doctest for missing output

* ci: install fr_FR locale to build docs

* doc: fix docs related to localization

* doc: fix docs related to localization

* feat: add flexible sorting capabilities to _format_helpers.formatting

In pint.delegates.formatter._format_helpers

The boolean `sort` argument will be deprecated.
Use `sort_fun` to specify the sorting function (default=sorted)
or None to keep units in the original order.

* Temporary fix for pluralization of units

* feat: sort by dimension in formatting

This PR adds the ability to sort units by the dimensionality  when formatting to string.

Close hgrecco#1926, hgrecco#1841

* chore!: drop support for Python 3.9 and NumPy < 1.23 due to NEP29

BREAKING CHANGE

* build: move dependencies to file, adding also appdirs, flexcache, flexparser

* chore: devendorize appdirs, flexcache, flexparser

As described here hgrecco/flexparser#5
fedora linux (and maybe other distros) avoid bundling libraries

The original design for Pint was from the time that packages with
no dependencies were a really good thing as installing extra
packages was hard. Now just pip install it.

So I have decided to devendor and add a requirements file.

* fix: typing improvements for defparser

- removed unused code
- remove typing from attributes which is set in the generic
- fix assertion due to untracked BOS

* refactor: run 'pyupgrade --py310-plus **/*.py'

* chore: configure ruff

Thanks @LecrisUT

close hgrecco#1892, hgrecco#1893

* style: run 'pre-commit run --all-files'

* ci: update minimal version in github ci. Python >= 3.10 NumPy>=1.23

* ci: add Python 3.12 to tests

* ci: fix 3.10 requires quote strings

* build: change minimum version of flexcache and flexparser

* fix: wrong use of formatting code

* fix: subformatters are within a formatr object

* fix: cache of decimal and float

* doc: explain angle and angular frequency

* chore: enable isort in ruff

* style: run 'pre-commit run --all-files'

* refactor: improve dim_sort readability

* feat: correct pluralization of localized units

This commits involves a heavy refactoring of the helper function for
the formatter. Briefly, before the same function that was generating
the string was splitting beween numerator and denominator. Now this
is done before to allow for correct pluralization.

* perf: speed up formatter

* fix: warning should be derived from UserWarning

* chore: Update `ruff` config

Close hgrecco#1955, hgrecco#1956

* fix: remove all mentions of `cumproduct` (hgrecco#1954)

numpy=2.0 will bring a lot of breaking changes, including the removal of cumproduct. numpy.cumproduct is already deprecated in favor of numpy.cumprod in 1.25; and cumprod is available in 1.23+

* Skip failing benchmark test (hgrecco#1981)

* avoid calling str on array (hgrecco#1959)

* Document defaults of pint.UnitRegistry (hgrecco#1919)

This updates the doc-string to include the defaults for all parameters.

* Fix doctests (hgrecco#1982)

* Fix siunitx format of integer powers with non_int_type=decimal.Decimal (hgrecco#1977)

* Implement numpy roll (hgrecco#1968)

* MNT: Handle trapz for numpy>=2 (hgrecco#1971)

trapz has been deprecated in favor of the newly available trapezoid
function. This wraps the new function and avoids a DeprecationWarning on
numpy>=2.

* Fix converting to offset units of higher dimension e.g. gauge pressure (hgrecco#1952)

* numpy2 support (hgrecco#1985)

* Add RIU to default_en.txt (hgrecco#1816)

* Array ufunc multiplication (hgrecco#1677)

* Fix TypeError when combining auto_reduce_dimensions=True and non_int_type=Decimal (hgrecco#1853)

* Detailed Error Message for `get_dimensionality()` (hgrecco#1874)

* move a change to 0.24 (hgrecco#1986)

* Add dBW, decibel watts (hgrecco#1292)

* Add check for delta unit to convert (hgrecco#1905)

* Avoid looping on large numpy arrays (hgrecco#1987)

* add packages using pint to ecosystem.rst (hgrecco#1960)

* use pytest skip for numpy2 test trapezoid (hgrecco#1988)

* add support for numpy.correlate and unit test (hgrecco#1990)

* depreciate ureg.__getitem__

* changes (hgrecco#2002)

* fix readme duplicate target (hgrecco#2004)

* Preparing for release 0.24

* Back to development: 0.25

* docs/ecosystem.rst: Add NEMO. (hgrecco#2010)

* Fix custom formatters needing registry (hgrecco#2011)

* Fix custom formatters needing registry

* add a doc note

* support 3.9 (hgrecco#2019)

changed matplotlib test to use a build that has a pypi wheel available for python3.10
changed TypeAlias import for 3.9 compat
changed min versions

* fix default format dimensionless  (hgrecco#2012)

* fix Custom formatters not working with modifiers (hgrecco#2021)

* fix babel tests issue (hgrecco#2020)

* skip babel tests if locales aren't installed (hgrecco#2022)

* add note on symbols to currency docs (hgrecco#2023)

* Preparing for release 0.24.1

* set changes to 0.25

* 🎨 Fix styling of docs headings in dark mode (hgrecco#2026)

* Add permille units with ‰ symbol (hgrecco#2033)

* ensure uncertainties does not depend on numpy (hgrecco#2001)

* Add ℓ as alternative for liter (hgrecco#2014)

* Added "mu" and "mc" prefixes. (hgrecco#2013)

* Fix cli uncertainty package import (hgrecco#2032)

* 2035 pandas3 (hgrecco#2036)

* [DOC] Update changelog (hgrecco#2034)

* add error for prefixed non multi units (hgrecco#1998)

* build: typing_extensions version

closes hgrecco#1996

* build: switch from appdirs to platformdirs

appdirs has been officially deprecated upstream, the replacement module
with more features is platformdirs.

Closes hgrecco#2028

* fix GenericPlainRegistry getattr type (hgrecco#2045)

* Replace references to the deprecated `UnitRegistry.default_format` (hgrecco#2058)

* fix: upgrade to flexparser>=0.4, exceptions are no longer dataclasses

* ci: add Python 3.13 to github ci

* Preparing for release 0.24.3

* Preparing for release 0.24.4

* Back to development: 0.25

* Add docs for testing module (hgrecco#2070)

* fix: Fix round function returning `float` instead of `int` (hgrecco#2089)

Fix hgrecco#2081

* bump typing_ext (hgrecco#2091)

* CODATA 2022 update (hgrecco#2049)

* qto.py: Make nan/inf magnitude checks accept uncertainties  (hgrecco#2093)

* qto.py: Make nan/inf magnitude checks accept uncertainties


Co-authored-by: Doron Behar <doron.behar@gmail.com>

* Typing: Fix return type of PlainQuantity.to (hgrecco#2090)

* Fix code style (hgrecco#2095)

* Fix syntax highlighting in overview doc (hgrecco#2098)

Remove bogus syntax highlighting on LICENSE in overview.rst

* updated uncertainties package documentation url (hgrecco#2099)

* Add conductivity dimension (hgrecco#2113)

* Add absorbance unit and dimension (hgrecco#2115)

* pin benchmark ubuntu

* Add membrane filtration flux and permeability dimensionality, and shorthand "LMH" (hgrecco#2122)

* Add membrane filtration flux and permeability

* Update CHANGES

* fix(docs): add graphviz package to render graphviz graphs

* refactor: pyupgrade --py310-plus **/*.py

* refactor: pyupgrade --py311-plus **/*.py

* build: start to move build and ci infrastructure to pixi

* build: create full and bench environments

* build: create numpy and full pixi environments

* build: update .gitignore

* build: add pyright environment and task

* build: bump minimum Python version for 3.11

* refactor: split try/except from if HAS_*/else in compat

The main reason behind this change is to be able to define
HAS_* as constants for typing purposes.

* refactor: delete unused file

* refactor: use TypeAlias

* test: refactor test_pint_eval as functions and incorporated uncertainty

* perf: benchmarks for pint_eval

* docs: update CHANGES

* fix: plain_tokenizer is currently named _plain_tokenizer

* build: remove python 3.9 and 3.10 from github workflows

* build: renamed full environment to all

* build: remove requirements.txt as it is now in pyproject.toml

* ci: remove unnecessary pip install

* build: specify package folder for hatch

* fix: remove -j auto because it is failing with current setup

* build: upgrade packages to make this sphinx work

* build: move doc building and testing to pixi

* build: install french locales for doctest

* refactor: reorganize and add typing to pint/pint_eval.py

* fix: now _plain_tokenizer is plain_tokenizer

* test: remove test_issue39 as np.matrix is deprecated

* test: missing number multiplying permille in test_issue1963

* test: numpy.trapz is deprectated in favour of numpy.trapezoid

* test: TestQuantityToCompact::test_nonnumeric_magnitudes should call to_compact, not compare

* test: upgrade to new formatter delegate

* test: UnitStrippedWarning is expected when copyto a non-quantity

* test: test should fail when xfail/xpassed is not working as expected

* test: remove print from test

* test: remove print from test

* test: xfail is incorrect here

* fix: split split_format to keep lru_cache but use warning every time

* test: trapezoid should be used for Numpy >= 2 and trapz otherwise

* test: trapz should be used for Numpy < 2

* test: trapezoid should be used for Numpy >= 2 and trapz otherwise

* refactor: improve pint-convert (hgrecco#2136)

- guard execution in __main__
- move code to functions

* ci: update setup-pixi to v0.8.2

> This release bumps @actions/cache to 4.0.0 which now integrates with the new cache service (v2) APIs.
https://github.com/prefix-dev/setup-pixi/releases/tag/v0.8.2

* build: upper bound for sphinx (hgrecco#2143)

Docs are not building with the lastest version of sphinx (v8.2.0).

```sh
Traceback
=========

      File ".../pint/.pixi/envs/docs/lib/python3.11/site-packages/sphinx/events.py", line 415, in emit
        raise ExtensionError(
    sphinx.errors.ExtensionError: Handler <function html_collect_pages at 0x11406d440> for event 'html-collect-pages' threw an exception (exception: module 'sphinx.util' has no attribute 'console')
```

* Pin sphinx version to allow docs to build (hgrecco#2144)

* chore(bench): update CodSpeed/action to v2 (hgrecco#1972)

Upgrading to the v2 of https://github.com/CodSpeedHQ/action will bring a better base run selection algorithm, better logging, and continued support.

* test: added slow/failing test for hgrecco#2146

* fix: using bfs algorithm for util.find_shortest_path

* chore: no longer need path argument to find_shortest_path, which is no longer recursive

* doc: added to CHANGES

* fix bench ci (hgrecco#2160)

* improve custom formatter docs (hgrecco#2159)

* chore: fix type error in pyproject.toml file (hgrecco#2163)

* Add pyproject update

---------

Signed-off-by: Michael Tiemann <72577720+MichaelTiemannOSC@users.noreply.github.com>
Signed-off-by: 72577720+MichaelTiemannOSC@users.noreply.github.com
Signed-off-by: MichaelTiemann <72577720+MichaelTiemannOSC@users.noreply.github.com>
Co-authored-by: Mamoru TASAKA <mtasaka@fedoraproject.org>
Co-authored-by: Hernan Grecco <hernan.grecco@gmail.com>
Co-authored-by: Michael Tiemann <72577720+MichaelTiemannOSC@users.noreply.github.com>
Co-authored-by: kadykov <62546709+kadykov@users.noreply.github.com>
Co-authored-by: Aleksandr Kadykov <kadykov@multitel.be>
Co-authored-by: Arjav Trivedi <at24@avfc.co.uk>
Co-authored-by: Justus Magin <keewis@posteo.de>
Co-authored-by: Alexander Krabbe <alkr@nanoq.gl>
Co-authored-by: Wouter Overmeire <lodagro@gmail.com>
Co-authored-by: Jules Chéron <43635101+jules-ch@users.noreply.github.com>
Co-authored-by: Sébastien Vallet <34129209+Saelyos@users.noreply.github.com>
Co-authored-by: Hernan Grecco <hgrecco@gmail.com>
Co-authored-by: Ryan May <rmay31@gmail.com>
Co-authored-by: Ben Beasley <code@musicinmybrain.net>
Co-authored-by: dcnadler <dcnadler@gmail.com>
Co-authored-by: Dana Nadler <nadler@amyris.com>
Co-authored-by: Varchas Gopalaswamy <vgop@lle.rochester.edu>
Co-authored-by: Sebastian Müller <mueller.seb@posteo.de>
Co-authored-by: andrewgsavage <andrewgsavage@gmail.com>
Co-authored-by: Justus Magin <keewis@users.noreply.github.com>
Co-authored-by: Matt Thompson <mattwthompson@protonmail.com>
Co-authored-by: David Linke <dalito@users.noreply.github.com>
Co-authored-by: Toon Verstraelen <Toon.Verstraelen@UGent.be>
Co-authored-by: Bhavin Patel <15210802+bpatel2107@users.noreply.github.com>
Co-authored-by: Peter Kraus <pk.kraus89@gmail.com>
Co-authored-by: Jonas Neubert <jn@jonasneubert.com>
Co-authored-by: tristannew <tristannew@ymail.com>
Co-authored-by: Matt Ettus <MattEttus@users.noreply.github.com>
Co-authored-by: Ivan Kondov <ivan.kondov@kit.edu>
Co-authored-by: Ben Elliston <bje@air.net.au>
Co-authored-by: Pascal Bourgault <bourgault.pascal@ouranos.ca>
Co-authored-by: Merrin Macleod <merrin.macleod@gmail.com>
Co-authored-by: Haris Musaefenidc <haris.musaefendic@gmail.com>
Co-authored-by: Tom Gillespie <tgbugs@gmail.com>
Co-authored-by: SPKorhonen <samuli-petrus.korhonen@iki.fi>
Co-authored-by: Pratyush Das <dpratyush.k@gmail.com>
Co-authored-by: mutricyl <118692416+mutricyl@users.noreply.github.com>
Co-authored-by: Steve Kowalik <steven@wedontsleep.org>
Co-authored-by: Bogdan Reznychenko <100156521+theodotk@users.noreply.github.com>
Co-authored-by: Marçal Gabaldà <mgab@users.noreply.github.com>
Co-authored-by: znichollscr <114576287+znichollscr@users.noreply.github.com>
Co-authored-by: Jules Chéron <jules.cheron@gmail.com>
Co-authored-by: Talley Lambert <talley.lambert@gmail.com>
Co-authored-by: Jellby <jellby@yahoo.com>
Co-authored-by: Doron Behar <doron.behar@gmail.com>
Co-authored-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com>
Co-authored-by: William Andrea <22385371+wjandrea@users.noreply.github.com>
Co-authored-by: Michael Weinold <23102087+michaelweinold@users.noreply.github.com>
Co-authored-by: Eskild Schroll-Fleischer <54531016+nneskildsf@users.noreply.github.com>
Co-authored-by: Mauro Silberberg <maurosilber@gmail.com>
Co-authored-by: Adrien Cacciaguerra <adrien.caccia@gmail.com>
Co-authored-by: Dean Malmgren <dean@planetfwd.com>
Co-authored-by: Igoreduardobraga <94845990+Igoreduardobraga@users.noreply.github.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
3.12 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants