-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Fix bug when multiplying Prefix and Quantity. #24909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug when multiplying Prefix and Quantity. #24909
Conversation
Previously, when multiplying a prefix and a quantity, the code would return 1 if the product of their scale factors was equal to 1. This resulted in incorrect output in some cases, such as when multiplying "milli" and "W", which would evaluate to 1 instead of W/1000. To fix this issue, the code has been updated to only return 1 when a prefix is multiplied by another prefix. When a prefix is multiplied by a quantity, the product of their scale factors is no longer checked for equality to 1.
✅ Hi, I am the SymPy bot. I'm here to help you write a release notes entry. Please read the guide on how to write release notes. Your release notes are in good order. Here is what the release notes will look like:
This will be added to https://github.com/sympy/sympy/wiki/Release-Notes-for-1.13. Click here to see the pull request description that was parsed.
Update The release notes on the wiki have been updated. |
I don't understand why from sympy.physics.units import milli, W # this is probably already imported in a unit's test file (in the sympy/physics/units/tests folder)
assert milli*W != 1 Also, when |
Benchmark results from GitHub Actions Lower numbers are good, higher numbers are bad. A ratio less than 1 Significantly changed benchmark results (PR vs master) Significantly changed benchmark results (master vs previous release) before after ratio
[8bd31f66] [a3068416]
<sympy-1.12rc1^0>
- 101±1ms 63.8±0.9ms 0.63 integrate.TimeIntegrationRisch02.time_doit(10)
- 99.4±1ms 63.6±0.8ms 0.64 integrate.TimeIntegrationRisch02.time_doit_risch(10)
Full benchmark results can be found as artifacts in GitHub Actions |
By default, the W (watt) has 1000 as scale_factor (related to SI system). Therefore, when taking the multiplication, the old code returns 1. About the test, thank you for reminding me, I will add the test. |
@@ -17,15 +17,16 @@ def test_prefix_operations(): | |||
|
|||
dodeca = Prefix('dodeca', 'dd', 1, base=12) | |||
|
|||
assert m * k == 1 | |||
assert m * k == S.One |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since 1==S.One, this would need to be tested using is
instead ==
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed accordingly. Thank you.
… as suggested in a comment
It's a relief to see this fixed. Thanks! In retrospect, we could have returned |
References to other Issues or PRs
Fixes #24832
Brief description of what is fixed or changed
Previously, when multiplying a prefix and a quantity, the code would return 1 if the product of their scale factors was equal to 1. This resulted in incorrect output in some cases, such as when multiplying "milli" and "W", which would evaluate to 1 instead of W/1000.
To fix this issue, the code has been updated to only return 1 when a prefix is multiplied by another prefix. When a prefix is multiplied by a quantity, the product of their scale factors is no longer checked for equality to 1.
Other comments
Release Notes