fixing errors deling with offsets in unit definitions#354
fixing errors deling with offsets in unit definitions#354MauriceHendrix merged 16 commits intomasterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #354 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 8
Lines 1564 1569 +5
Branches 371 373 +2
=========================================
+ Hits 1564 1569 +5
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
|
The offset bit won't work. Offsets are supposed to change the unit, which The presence of an offset that isn't 0 should be a warning or an error for all units (dimensionless or not) |
|
now throwing error for dimentionless + offset other non-0 offsets |
looks like we just use |
|
aah sorry I thought you wanted to make a distinction between dimentionless + offset and non-dimensionless + non-0 offset :) I've changed it to throw ValueError for non-0 offsets and indeed no need to carry the offset. |
| # Trying to convert dimensionless gives an error but we can convert to it | ||
| if quantity.units == self._registry.dimensionless: | ||
| quantity, unit = 1 * unit, quantity.units | ||
| return 1 / quantity.to(unit) |
There was a problem hiding this comment.
I don't understand what this code does, at all!
Could you add some comments to explain it?
There was a problem hiding this comment.
Indeed it looks like a pint error, you can convert one way, but not the other way.
actually I think it should be quantity.magnitude / quantity.to(unit) rather than 1 / quantity.to(unit)
so that 2 meters become 4 half meters en 3 half meters become 1.5 meter i.e.
def test_dimensionless_multiplier2(self):
model = load_model('dimensionless_multiplier2.cellml')
meter = model.units.get_unit('meter')
half_meter = model.units.get_unit('half_meter')
cf1 = model.units.convert(2 * meter, half_meter).magnitude
cf2 = model.units.convert(3 * half_meter, meter).magnitude
assert cf1 == 4.0
assert cf2 == 1.5
Co-authored-by: Michael Clerx <MichaelClerx@users.noreply.github.com>
MichaelClerx
left a comment
There was a problem hiding this comment.
Just one question left
Co-authored-by: Michael Clerx <MichaelClerx@users.noreply.github.com>
Description
Fixes errors dealing with:
Motivation and Context
fixes #351
Types of changes
Documentation checklist
Testing