Skip to content

Nonreducing#1993

Open
andrewgsavage wants to merge 13 commits intohgrecco:masterfrom
andrewgsavage:nonreducing
Open

Nonreducing#1993
andrewgsavage wants to merge 13 commits intohgrecco:masterfrom
andrewgsavage:nonreducing

Conversation

@andrewgsavage
Copy link
Copy Markdown
Collaborator

  • Closes # (insert issue number)
  • Executed pre-commit run --all-files with no errors
  • The change is fully covered by automated unit tests
  • Documented in docs/ as appropriate
  • Added an entry to the CHANGES file

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented May 22, 2024

Merging this PR will not alter performance

✅ 448 untouched benchmarks


Comparing andrewgsavage:nonreducing (af3cd64) with master (86f37c0)

Open in CodSpeed

@andrewgsavage
Copy link
Copy Markdown
Collaborator Author

I think support for this can be added in a few functions, eg

mm_per_mm = ureg.NonReducingUnitsContainer([ureg.mm, 1/ureg.mm])
Quantity(1, mm_per_mm)
Quantity(1,"").to(mm_per_mm)

I am unsure on using this in more places as it would change behaviour where units currently cancel out.

@andrewgsavage
Copy link
Copy Markdown
Collaborator Author

I am unsure on using this in more places as it would change behaviour where units currently cancel out.

Could set behaviour with a registry setting like auto_reduce_dimensions

@mutricyl
Copy link
Copy Markdown
Contributor

mutricyl commented Feb 9, 2026

For information I have au use case that made me open #2256
I often use transfer function in my industry. You have to compute the response of the system when excited and divide it by the amplitude of the exciting process. To be more specific vessel motion (meter) divided by wave amplitude (meter).
As I always normalize results with wave amplitude (m), I use a custom formatter to force displaying dimensionless to m/m

@andrewgsavage
Copy link
Copy Markdown
Collaborator Author

For information I have au use case that made me open #2256 I often use transfer function in my industry. You have to compute the response of the system when excited and divide it by the amplitude of the exciting process. To be more specific vessel motion (meter) divided by wave amplitude (meter). As I always normalize results with wave amplitude (m), I use a custom formatter to force displaying dimensionless to m/m

would you be willing to look through this PR and review it?

@andrewgsavage
Copy link
Copy Markdown
Collaborator Author

For information I have au use case that made me open #2256 I often use transfer function in my industry. You have to compute the response of the system when excited and divide it by the amplitude of the exciting process. To be more specific vessel motion (meter) divided by wave amplitude (meter). As I always normalize results with wave amplitude (m), I use a custom formatter to force displaying dimensionless to m/m

would you be willing to look through this PR and review it?

poke @mutricyl

@mutricyl
Copy link
Copy Markdown
Contributor

mutricyl commented Feb 16, 2026 via email

Copy link
Copy Markdown
Contributor

@mutricyl mutricyl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andrew,
I have played a little bit with the NonReducing feature but I came accross the following issue:

ureg_t = UnitRegistry(auto_reduce_units=True)
ureg_f = UnitRegistry(auto_reduce_units=False)

ureg_t('1.0 kN.m') # fine: <Quantity(1.0, 'kilonewton * meter')>
ureg_f('1.0 kN.m') # NOK: 
# pint\util.py", line 628, in __copy__
#     out._one = self._one
#               ^^^^^^^^^
# AttributeError: 'NonReducingUnitsContainer' object has no attribute '_one'
ureg_f.Unit('kN.m') # OK; <Unit('kilonewton * meter')>
ureg_f(kN) # OK: <Quantity(1, 'kilonewton')>
ureg_f('m/s/m') # NOK: same AttributeError as above in pint.util.UnitsContainer.__copy__

Parsing of a new Quantity with auto_reduce_units set to false sometimes fails when it come to copy the UnitContainer. The Error is not present when auto_reduce_units is set to tue or when Unit method is used.

Co-authored-by: mutricyl <118692416+mutricyl@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants