Skip to content
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

Add percent support, bump pint version #219

Merged
merged 1 commit into from
Aug 1, 2024
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
2 changes: 1 addition & 1 deletion gemd/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.1.6"
__version__ = "2.1.7"
23 changes: 18 additions & 5 deletions gemd/units/citrine_en.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Citrine customized units input file for Pint, based explicitly on the Pint defaults as
# included release 0.20 (https://github.com/hgrecco/pint/releases/tag/0.20). The Pint Authors hold
# copyright and are documented in https://github.com/hgrecco/pint/blob/0.20/AUTHORS.
# included release 0.23 (https://github.com/hgrecco/pint/releases/tag/0.23). The Pint Authors hold
# copyright and are documented in https://github.com/hgrecco/pint/blob/0.23/AUTHORS.
#
# The original copyright statement for the constants file reads:
#
Expand Down Expand Up @@ -106,6 +106,8 @@
#### PREFIXES ####

# decimal prefixes
quecto- = 1e-30 = q-
ronto- = 1e-27 = r-
yocto- = 1e-24 = y-
zepto- = 1e-21 = z-
atto- = 1e-18 = a-
Expand All @@ -128,6 +130,8 @@ peta- = 1e15 = P-
exa- = 1e18 = E-
zetta- = 1e21 = Z-
yotta- = 1e24 = Y-
ronna- = 1e27 = R-
quetta- = 1e30 = Q-

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

# Ratios
percent = 0.01 = % = pct
permille = 0.001 = ‰ = per_thousand
ppm = 1e-6 = per_million

# Length
angstrom = 1e-10 * meter = Å = ångström = Angstrom = Ångstrom = Å
micron = micrometer = µ = Micron
micron = micrometer = µ = μ = Micron
fermi = femtometer = fm = Fermi
light_year = speed_of_light * julian_year = ly = lightyear = Light_Year = Lightyear
astronomical_unit = 149597870700 * meter = au = Astronomical_Unit # since Aug 2012
Expand Down Expand Up @@ -468,6 +477,10 @@ atomic_unit_of_electric_field = e * k_C / a_0 ** 2 = a_u_electric_field
# Electric displacement field
[electric_displacement_field] = [charge] / [area]

# Reduced electric field
[reduced_electric_field] = [electric_field] * [area]
townsend = 1e-21 * V * m^2 = Td = Townsend

# Resistance
[resistance] = [electric_potential] / [current]
ohm = volt / ampere = Ω = Ohm
Expand Down Expand Up @@ -707,10 +720,10 @@ neper = 1 ; logbase: 2.71828182845904523536028747135266249775724709369995; logfa
# @group Textile
# tex = gram / kilometer = Tt
# dtex = decitex
# denier = gram / (9 * kilometer) = den = Td
# denier = gram / (9 * kilometer) = den
# jute = pound / (14400 * yard) = Tj
# aberdeen = jute = Ta
# RKM = kgf * 1000 / tex
# RKM = gf / tex
#
# number_english = 840 * yard / pound = Ne = NeC = ECC
# number_meter = kilometer / kilogram = Nm
Expand Down
8 changes: 1 addition & 7 deletions gemd/units/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ def _deploy_default_files() -> Tuple[Path, Path]:
_ALLOWED_OPERATORS = {".", "+", "-", "*", "/", "//", "^", "**", "(", ")"}


def _space_after_minus_preprocessor(input_string: str) -> str:
"""A preprocessor that protects against a pint < 0.21 bug."""
return re.sub(r"(?<=-)\s+(?=\d)", "", input_string)


def _scientific_notation_preprocessor(input_string: str) -> str:
"""Preprocessor that converts x * 10 ** y format to xEy."""
def _as_scientific(matchobj: re.Match) -> str:
Expand Down Expand Up @@ -402,8 +397,7 @@ def change_definitions_file(filename: str = None):
# Need to re-verify path because of some slippiness around tmp on macOS
updated = (Path.cwd() / target.name).resolve(strict=True)
_REGISTRY = _ScaleFactorRegistry(filename=updated,
preprocessors=[_space_after_minus_preprocessor,
_scientific_notation_preprocessor,
preprocessors=[_scientific_notation_preprocessor,
_scaling_preprocessor
],
autoconvert_offset_to_baseunit=True
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pint==0.20
pint==0.21
deprecation==2.1.0
typing-extensions==4.8.0
importlib-resources==5.3.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
'tests.units': ['test_units.txt']
},
install_requires=[
"pint>=0.20,<0.24",
"pint>=0.21,<0.24",
"deprecation>=2.1.0,<3",
"typing_extensions>=4.8,<5",
"importlib-resources>=5.3,<7"
Expand Down