Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions physical_quantities/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ The first public release. This is a further tidy-up after the 0.2.0 extraction:

### Fixed

- (since 0.3.0rc6) The electronvolt is exactly 1.602176634×10⁻¹⁹ J (since the 2019 SI redefinition); it was 1.60218×10⁻¹⁹ J. The atomic mass unit is 1.66053906892×10⁻²⁷ kg (CODATA 2022); it was 1.66054×10⁻²⁷ kg. With a tight tolerance, `1 eV` didn't match `1.602176634e-19 J`.
- (since 0.3.0rc6) `stones` is recognised as the plural of `stone`. Before, `2 stones` wasn't read as a mass.
- (since 0.3.0rc6) A bare `da` is documented and tested as a deci-are (d + a, 10 m²), not the deca prefix on its own. This is unchanged behaviour.
- (since 0.3.0rc5) A value that is a list, with a unit, is converted value by value: `{1, 2} km`, `1,2~\mathrm{km}` (LaTeX), `plus_minus 2 km` and `\pm 2~\mathrm{km}` give `standard_values` of 1000 and 2000 (or −2000 and 2000). Before, the unit factor multiplied the list as a whole, and `parse_quantity` raised `QuantityParseError`.
- The roentgen was converted as kelvin per kilogram; it is 2.58×10⁻⁴ C/kg (ampere·second per kilogram).
- The imperial pint was 0.00056826 m³; it is 0.00056826125 m³, so that 8 pints make a gallon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ class Unit(NamedTuple):
Unit("metricton", "t", "(10**3*kilogram)", ("tonne",), ("tonnes",)),
Unit("neper", "Np", "(1)", ("Neper",), ("nepers", "Nepers")),
Unit("bel", "B", "((1/2)*2.30258509299405)", ("Bel",), ("bels", "Bels")), # log(10) = 2.30258509299405
Unit("electronvolt", "eV", "(1.60218*10**(-19)*joule)", (), ("electronvolts",)),
Unit("atomic_mass_unit", "u", "(1.66054*10**(-27)*kilogram)", (), ("atomic_mass_units",)),
Unit("electronvolt", "eV", "(1.602176634*10**(-19)*joule)", (), ("electronvolts",)),
Unit("atomic_mass_unit", "u", "(1.66053906892*10**(-27)*kilogram)", (), ("atomic_mass_units",)),
Unit("angstrom", "Å", "(10**(-10)*metre)", ("Angstrom", "Ångström"), ("angstroms", "Angstroms")),
)

Expand All @@ -144,6 +144,7 @@ class Unit(NamedTuple):
Unit("astronomical_unit", "au", "(149597870700*metre)", (), ("astronomical_units",)),
Unit("nautical_mile", "nmi", "(1852*metre)", (), ("nautical_miles", "nauticalmiles")), # symbol from Wikipedia
Unit("knot", "kn", "((1852/3600)*metre/second)", (), ("knots",)), # symbol from Wikipedia
# A bare "da" is read as d (deci) + a (are), a deci-are of 10 m^2, not as the deca prefix on its own.
Unit("are", "a", "(10**2*metre**2)", (), ("ares",)),
Unit("hectare", "ha", "(10**4*metre**2)", (), ("hectares",)),
Unit("bar", "bar", "(10**5*pascal)", (), ("bars",)),
Expand All @@ -169,7 +170,7 @@ class Unit(NamedTuple):
Unit("gallon", "gal", "(0.00454609*metre**3)", (), ("gallons",)),
Unit("ounce", "oz", "(28.349523125*gram)", (), ("ounces",)),
Unit("pound", "lb", "(0.45359237*kilogram)", (), ("pounds",)),
Unit("stone", "st", "(6.35029318*kilogram)"),
Unit("stone", "st", "(6.35029318*kilogram)", (), ("stones",)),
)

AnyUnit = BaseUnit | Unit
Expand Down
21 changes: 21 additions & 0 deletions physical_quantities/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ def _si_value(text):
return value


class TestUnitTableValues:
@pytest.mark.parametrize(
"text, expected",
[
# Exact since the 2019 SI redefinition
("1 eV", "1.602176634e-19 J"),
# CODATA 2022
("1 u", "1.66053906892e-27 kg"),
("2 stones", "12.70058636 kg"),
# A bare "da" is a deci-are, not the deca prefix
("1 da", "10 m^2"),
],
)
def test_value_in_si(self, text, expected):
value, expected_value = _si_value(text), _si_value(expected)
assert abs(value - expected_value) <= 1e-12 * abs(expected_value)

def test_stone_plural(self):
assert repr(parse_quantity("2 stones", QuantityParams())) == "PhysicalQuantity(value='2', unit='stone')"


class TestDimensions:
@pytest.mark.parametrize(
"text, base_dimension",
Expand Down
204 changes: 204 additions & 0 deletions tools/parity/expected_changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,23 @@
"value_latex": "10"
}
},
"quantity.parse|legacy|10 atomic_mass_unit": {
"reason": "physical_quantities: the electronvolt is exactly 1.602176634e-19 J (2019 SI) and the atomic mass unit 1.66053906892e-27 kg (CODATA 2022); were 1.60218e-19 J and 1.66054e-27 kg",
"value": {
"content": "10 atomic_mass_unit",
"dimension": "(41513476723/25000000000)*10**3*mass/10**27",
"expanded_unit": "(41513476723/25000000000)*10**3*gram/10**27",
"latex": "10~\\mathrm{atomic_mass_unit}",
"messages": [],
"standard_unit": "gram",
"standard_value": "10*41513476723/25000000000000000000000000000000000",
"unit": "atomic_mass_unit",
"unit_factor": "41513476723/25000000000000000000000000000000000",
"unit_latex": "\\mathrm{atomic_mass_unit}",
"value": "10",
"value_latex": "10"
}
},
"quantity.parse|legacy|10 deg": {
"reason": "units: angles in radians (radian = 1); degree is pi/180 (was 1/360 of a turn, inconsistent with angleminute)",
"value": {
Expand Down Expand Up @@ -682,6 +699,40 @@
"value_latex": "10"
}
},
"quantity.parse|legacy|10 eV": {
"reason": "physical_quantities: the electronvolt is exactly 1.602176634e-19 J (2019 SI) and the atomic mass unit 1.66053906892e-27 kg (CODATA 2022); were 1.60218e-19 J and 1.66054e-27 kg",
"value": {
"content": "10 electronvolt",
"dimension": "(801088317/500000000)*length**2*10**3*mass/(10**19*time**2)",
"expanded_unit": "(801088317/500000000)*metre**2*10**3*gram/(10**19*second**2)",
"latex": "10~\\mathrm{electronvolt}",
"messages": [],
"standard_unit": "gram*metre**2/second**2",
"standard_value": "10*801088317/5000000000000000000000000",
"unit": "eV",
"unit_factor": "801088317/5000000000000000000000000",
"unit_latex": "\\mathrm{electronvolt}",
"value": "10",
"value_latex": "10"
}
},
"quantity.parse|legacy|10 electronvolt": {
"reason": "physical_quantities: the electronvolt is exactly 1.602176634e-19 J (2019 SI) and the atomic mass unit 1.66053906892e-27 kg (CODATA 2022); were 1.60218e-19 J and 1.66054e-27 kg",
"value": {
"content": "10 electronvolt",
"dimension": "(801088317/500000000)*length**2*10**3*mass/(10**19*time**2)",
"expanded_unit": "(801088317/500000000)*metre**2*10**3*gram/(10**19*second**2)",
"latex": "10~\\mathrm{electronvolt}",
"messages": [],
"standard_unit": "gram*metre**2/second**2",
"standard_value": "10*801088317/5000000000000000000000000",
"unit": "electronvolt",
"unit_factor": "801088317/5000000000000000000000000",
"unit_latex": "\\mathrm{electronvolt}",
"value": "10",
"value_latex": "10"
}
},
"quantity.parse|legacy|10 kg m/s^2 + 10 kg m/s^2": {
"reason": "units: FeedbackTag removed; reverted-unit facts now exposed as plain RevertedUnit(before, marked, after) records, not (id, tag, inputs) triples",
"value": {
Expand Down Expand Up @@ -1159,6 +1210,23 @@
"value_latex": "10"
}
},
"quantity.parse|legacy|10 u": {
"reason": "physical_quantities: the electronvolt is exactly 1.602176634e-19 J (2019 SI) and the atomic mass unit 1.66053906892e-27 kg (CODATA 2022); were 1.60218e-19 J and 1.66054e-27 kg",
"value": {
"content": "10 atomic_mass_unit",
"dimension": "(41513476723/25000000000)*10**3*mass/10**27",
"expanded_unit": "(41513476723/25000000000)*10**3*gram/10**27",
"latex": "10~\\mathrm{atomic_mass_unit}",
"messages": [],
"standard_unit": "gram",
"standard_value": "10*41513476723/25000000000000000000000000000000000",
"unit": "u",
"unit_factor": "41513476723/25000000000000000000000000000000000",
"unit_latex": "\\mathrm{atomic_mass_unit}",
"value": "10",
"value_latex": "10"
}
},
"quantity.parse|legacy|100* Pa": {
"reason": "units: FeedbackTag removed; reverted-unit facts now exposed as plain RevertedUnit(before, marked, after) records, not (id, tag, inputs) triples",
"value": {
Expand Down Expand Up @@ -3123,6 +3191,23 @@
"value_latex": "10"
}
},
"quantity.parse|natural|10 atomic_mass_unit": {
"reason": "physical_quantities: the electronvolt is exactly 1.602176634e-19 J (2019 SI) and the atomic mass unit 1.66053906892e-27 kg (CODATA 2022); were 1.60218e-19 J and 1.66054e-27 kg",
"value": {
"content": "10 atomic_mass_unit",
"dimension": "(41513476723/25000000000)*10**3*mass/10**27",
"expanded_unit": "(41513476723/25000000000)*10**3*gram/10**27",
"latex": "10~\\mathrm{atomic_mass_unit}",
"messages": [],
"standard_unit": "gram",
"standard_value": "10*41513476723/25000000000000000000000000000000000",
"unit": "atomic_mass_unit",
"unit_factor": "41513476723/25000000000000000000000000000000000",
"unit_latex": "\\mathrm{atomic_mass_unit}",
"value": "10",
"value_latex": "10"
}
},
"quantity.parse|natural|10 deg": {
"reason": "units: angles in radians (radian = 1); degree is pi/180 (was 1/360 of a turn, inconsistent with angleminute)",
"value": {
Expand Down Expand Up @@ -3157,6 +3242,40 @@
"value_latex": "10"
}
},
"quantity.parse|natural|10 eV": {
"reason": "physical_quantities: the electronvolt is exactly 1.602176634e-19 J (2019 SI) and the atomic mass unit 1.66053906892e-27 kg (CODATA 2022); were 1.60218e-19 J and 1.66054e-27 kg",
"value": {
"content": "10 electronvolt",
"dimension": "(801088317/500000000)*length**2*10**3*mass/(10**19*time**2)",
"expanded_unit": "(801088317/500000000)*metre**2*10**3*gram/(10**19*second**2)",
"latex": "10~\\mathrm{electronvolt}",
"messages": [],
"standard_unit": "gram*metre**2/second**2",
"standard_value": "10*801088317/5000000000000000000000000",
"unit": "eV",
"unit_factor": "801088317/5000000000000000000000000",
"unit_latex": "\\mathrm{electronvolt}",
"value": "10",
"value_latex": "10"
}
},
"quantity.parse|natural|10 electronvolt": {
"reason": "physical_quantities: the electronvolt is exactly 1.602176634e-19 J (2019 SI) and the atomic mass unit 1.66053906892e-27 kg (CODATA 2022); were 1.60218e-19 J and 1.66054e-27 kg",
"value": {
"content": "10 electronvolt",
"dimension": "(801088317/500000000)*length**2*10**3*mass/(10**19*time**2)",
"expanded_unit": "(801088317/500000000)*metre**2*10**3*gram/(10**19*second**2)",
"latex": "10~\\mathrm{electronvolt}",
"messages": [],
"standard_unit": "gram*metre**2/second**2",
"standard_value": "10*801088317/5000000000000000000000000",
"unit": "electronvolt",
"unit_factor": "801088317/5000000000000000000000000",
"unit_latex": "\\mathrm{electronvolt}",
"value": "10",
"value_latex": "10"
}
},
"quantity.parse|natural|10 kg m/s^2 + 10 kg m/s^2": {
"reason": "units: FeedbackTag removed; reverted-unit facts now exposed as plain RevertedUnit(before, marked, after) records, not (id, tag, inputs) triples",
"value": {
Expand Down Expand Up @@ -3634,6 +3753,23 @@
"value_latex": "10"
}
},
"quantity.parse|natural|10 u": {
"reason": "physical_quantities: the electronvolt is exactly 1.602176634e-19 J (2019 SI) and the atomic mass unit 1.66053906892e-27 kg (CODATA 2022); were 1.60218e-19 J and 1.66054e-27 kg",
"value": {
"content": "10 atomic_mass_unit",
"dimension": "(41513476723/25000000000)*10**3*mass/10**27",
"expanded_unit": "(41513476723/25000000000)*10**3*gram/10**27",
"latex": "10~\\mathrm{atomic_mass_unit}",
"messages": [],
"standard_unit": "gram",
"standard_value": "10*41513476723/25000000000000000000000000000000000",
"unit": "u",
"unit_factor": "41513476723/25000000000000000000000000000000000",
"unit_latex": "\\mathrm{atomic_mass_unit}",
"value": "10",
"value_latex": "10"
}
},
"quantity.parse|natural|100* Pa": {
"reason": "units: FeedbackTag removed; reverted-unit facts now exposed as plain RevertedUnit(before, marked, after) records, not (id, tag, inputs) triples",
"value": {
Expand Down Expand Up @@ -4374,6 +4510,23 @@
"value_latex": "10"
}
},
"quantity.parse|strict_all|10 atomic_mass_unit": {
"reason": "physical_quantities: the electronvolt is exactly 1.602176634e-19 J (2019 SI) and the atomic mass unit 1.66053906892e-27 kg (CODATA 2022); were 1.60218e-19 J and 1.66054e-27 kg",
"value": {
"content": "10 atomic_mass_unit",
"dimension": "(41513476723/25000000000)*10**3*mass/10**27",
"expanded_unit": "(41513476723/25000000000)*10**3*gram/10**27",
"latex": "10~\\mathrm{atomic_mass_unit}",
"messages": [],
"standard_unit": "gram",
"standard_value": "10*41513476723/25000000000000000000000000000000000",
"unit": "atomic_mass_unit",
"unit_factor": "41513476723/25000000000000000000000000000000000",
"unit_latex": "\\mathrm{atomic_mass_unit}",
"value": "10",
"value_latex": "10"
}
},
"quantity.parse|strict_all|10 deg": {
"reason": "units: angles in radians (radian = 1); degree is pi/180 (was 1/360 of a turn, inconsistent with angleminute)",
"value": {
Expand Down Expand Up @@ -4408,6 +4561,40 @@
"value_latex": "10"
}
},
"quantity.parse|strict_all|10 eV": {
"reason": "physical_quantities: the electronvolt is exactly 1.602176634e-19 J (2019 SI) and the atomic mass unit 1.66053906892e-27 kg (CODATA 2022); were 1.60218e-19 J and 1.66054e-27 kg",
"value": {
"content": "10 electronvolt",
"dimension": "(801088317/500000000)*length**2*10**3*mass/(10**19*time**2)",
"expanded_unit": "(801088317/500000000)*metre**2*10**3*gram/(10**19*second**2)",
"latex": "10~\\mathrm{electronvolt}",
"messages": [],
"standard_unit": "gram*metre**2/second**2",
"standard_value": "10*801088317/5000000000000000000000000",
"unit": "eV",
"unit_factor": "801088317/5000000000000000000000000",
"unit_latex": "\\mathrm{electronvolt}",
"value": "10",
"value_latex": "10"
}
},
"quantity.parse|strict_all|10 electronvolt": {
"reason": "physical_quantities: the electronvolt is exactly 1.602176634e-19 J (2019 SI) and the atomic mass unit 1.66053906892e-27 kg (CODATA 2022); were 1.60218e-19 J and 1.66054e-27 kg",
"value": {
"content": "10 electronvolt",
"dimension": "(801088317/500000000)*length**2*10**3*mass/(10**19*time**2)",
"expanded_unit": "(801088317/500000000)*metre**2*10**3*gram/(10**19*second**2)",
"latex": "10~\\mathrm{electronvolt}",
"messages": [],
"standard_unit": "gram*metre**2/second**2",
"standard_value": "10*801088317/5000000000000000000000000",
"unit": "electronvolt",
"unit_factor": "801088317/5000000000000000000000000",
"unit_latex": "\\mathrm{electronvolt}",
"value": "10",
"value_latex": "10"
}
},
"quantity.parse|strict_all|10 g/sm": {
"reason": "units: FeedbackTag removed; reverted-unit facts now exposed as plain RevertedUnit(before, marked, after) records, not (id, tag, inputs) triples",
"value": {
Expand Down Expand Up @@ -5102,6 +5289,23 @@
"value_latex": "10"
}
},
"quantity.parse|strict_all|10 u": {
"reason": "physical_quantities: the electronvolt is exactly 1.602176634e-19 J (2019 SI) and the atomic mass unit 1.66053906892e-27 kg (CODATA 2022); were 1.60218e-19 J and 1.66054e-27 kg",
"value": {
"content": "10 atomic_mass_unit",
"dimension": "(41513476723/25000000000)*10**3*mass/10**27",
"expanded_unit": "(41513476723/25000000000)*10**3*gram/10**27",
"latex": "10~\\mathrm{atomic_mass_unit}",
"messages": [],
"standard_unit": "gram",
"standard_value": "10*41513476723/25000000000000000000000000000000000",
"unit": "u",
"unit_factor": "41513476723/25000000000000000000000000000000000",
"unit_latex": "\\mathrm{atomic_mass_unit}",
"value": "10",
"value_latex": "10"
}
},
"quantity.parse|strict_all|10*pi kilogrammetre/second^2": {
"reason": "units: FeedbackTag removed; reverted-unit facts now exposed as plain RevertedUnit(before, marked, after) records, not (id, tag, inputs) triples",
"value": {
Expand Down
Loading