Skip to content

Commit 57827c0

Browse files
authored
Add percent support, bump pint version (#219)
1 parent f3be77f commit 57827c0

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

gemd/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.1.6"
1+
__version__ = "2.1.7"

gemd/units/citrine_en.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Citrine customized units input file for Pint, based explicitly on the Pint defaults as
2-
# included release 0.20 (https://github.com/hgrecco/pint/releases/tag/0.20). The Pint Authors hold
3-
# copyright and are documented in https://github.com/hgrecco/pint/blob/0.20/AUTHORS.
2+
# included release 0.23 (https://github.com/hgrecco/pint/releases/tag/0.23). The Pint Authors hold
3+
# copyright and are documented in https://github.com/hgrecco/pint/blob/0.23/AUTHORS.
44
#
55
# The original copyright statement for the constants file reads:
66
#
@@ -106,6 +106,8 @@
106106
#### PREFIXES ####
107107

108108
# decimal prefixes
109+
quecto- = 1e-30 = q-
110+
ronto- = 1e-27 = r-
109111
yocto- = 1e-24 = y-
110112
zepto- = 1e-21 = z-
111113
atto- = 1e-18 = a-
@@ -128,6 +130,8 @@ peta- = 1e15 = P-
128130
exa- = 1e18 = E-
129131
zetta- = 1e21 = Z-
130132
yotta- = 1e24 = Y-
133+
ronna- = 1e27 = R-
134+
quetta- = 1e30 = Q-
131135

132136
# binary_prefixes
133137
kibi- = 2**10 = Ki-
@@ -189,9 +193,14 @@ byte = 8 * bit = B = octet = Byte = Octet
189193
# byte = 8 * bit = _ = octet
190194
## NOTE: B (byte) symbol can conflict with Bell
191195

196+
# Ratios
197+
percent = 0.01 = % = pct
198+
permille = 0.001 = ‰ = per_thousand
199+
ppm = 1e-6 = per_million
200+
192201
# Length
193202
angstrom = 1e-10 * meter = Å = ångström = Angstrom = Ångstrom = Å
194-
micron = micrometer = µ = Micron
203+
micron = micrometer = µ = μ = Micron
195204
fermi = femtometer = fm = Fermi
196205
light_year = speed_of_light * julian_year = ly = lightyear = Light_Year = Lightyear
197206
astronomical_unit = 149597870700 * meter = au = Astronomical_Unit # since Aug 2012
@@ -468,6 +477,10 @@ atomic_unit_of_electric_field = e * k_C / a_0 ** 2 = a_u_electric_field
468477
# Electric displacement field
469478
[electric_displacement_field] = [charge] / [area]
470479

480+
# Reduced electric field
481+
[reduced_electric_field] = [electric_field] * [area]
482+
townsend = 1e-21 * V * m^2 = Td = Townsend
483+
471484
# Resistance
472485
[resistance] = [electric_potential] / [current]
473486
ohm = volt / ampere = Ω = Ohm
@@ -707,10 +720,10 @@ neper = 1 ; logbase: 2.71828182845904523536028747135266249775724709369995; logfa
707720
# @group Textile
708721
# tex = gram / kilometer = Tt
709722
# dtex = decitex
710-
# denier = gram / (9 * kilometer) = den = Td
723+
# denier = gram / (9 * kilometer) = den
711724
# jute = pound / (14400 * yard) = Tj
712725
# aberdeen = jute = Ta
713-
# RKM = kgf * 1000 / tex
726+
# RKM = gf / tex
714727
#
715728
# number_english = 840 * yard / pound = Ne = NeC = ECC
716729
# number_meter = kilometer / kilogram = Nm

gemd/units/impl.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ def _deploy_default_files() -> Tuple[Path, Path]:
4444
_ALLOWED_OPERATORS = {".", "+", "-", "*", "/", "//", "^", "**", "(", ")"}
4545

4646

47-
def _space_after_minus_preprocessor(input_string: str) -> str:
48-
"""A preprocessor that protects against a pint < 0.21 bug."""
49-
return re.sub(r"(?<=-)\s+(?=\d)", "", input_string)
50-
51-
5247
def _scientific_notation_preprocessor(input_string: str) -> str:
5348
"""Preprocessor that converts x * 10 ** y format to xEy."""
5449
def _as_scientific(matchobj: re.Match) -> str:
@@ -402,8 +397,7 @@ def change_definitions_file(filename: str = None):
402397
# Need to re-verify path because of some slippiness around tmp on macOS
403398
updated = (Path.cwd() / target.name).resolve(strict=True)
404399
_REGISTRY = _ScaleFactorRegistry(filename=updated,
405-
preprocessors=[_space_after_minus_preprocessor,
406-
_scientific_notation_preprocessor,
400+
preprocessors=[_scientific_notation_preprocessor,
407401
_scaling_preprocessor
408402
],
409403
autoconvert_offset_to_baseunit=True

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pint==0.20
1+
pint==0.21
22
deprecation==2.1.0
33
typing-extensions==4.8.0
44
importlib-resources==5.3.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
'tests.units': ['test_units.txt']
3434
},
3535
install_requires=[
36-
"pint>=0.20,<0.24",
36+
"pint>=0.21,<0.24",
3737
"deprecation>=2.1.0,<3",
3838
"typing_extensions>=4.8,<5",
3939
"importlib-resources>=5.3,<7"

0 commit comments

Comments
 (0)