Skip to content

Commit

Permalink
Fix compatibility with pint 0.24 (#56)
Browse files Browse the repository at this point in the history
* Fix compatibility with pint 0.24

* Hotfix for incompatible numpy versions in python 3.9

* restore compatibility to pint 0.23

* Add notice to remove extra check after dropping python 3.9
  • Loading branch information
ManuelHu authored Jun 20, 2024
1 parent 78b6cc4 commit 9d45757
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ classifiers = [
]
requires-python = ">=3.9"
dependencies = [
"numpy",
"numpy<2.0 ; python_version <= '3.9'",
"numpy ; python_version >= '3.10'",
"pint",
"pyg4ometry",
"pylegendmeta>=v0.9.0a2",
Expand Down
9 changes: 6 additions & 3 deletions src/legendoptics/pyg4utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def pyg4_def_scint_by_particle_type(mat, scint_cfg: ScintConfig) -> None:

@pint.register_unit_format("gdml")
def _gdml_format(unit, registry, **options):
proc = {u.replace("µ", "u"): e for u, e in unit.items()}
return pint.formatter(
proc = {ureg._get_symbol(u).replace("µ", "u"): e for u, e in unit.items()}
return pint.formatting.formatter(
proc.items(),
as_ratio=True,
single_denominator=False,
Expand All @@ -89,8 +89,11 @@ def _val_pint_to_gdml(v):

base_unit = v.units

unit = f"{base_unit:~gdml}"
# TODO: drop the extra check for dimensionless quantities after dropping support for pint <= 0.23
unit = "" if v.check("1") else f"{base_unit:gdml}"
assert unit == f"{base_unit:~}".replace(" ", "").replace("µ", "u")
assert "dimensionless" not in unit

msg = f"Unit pint->gdml: {unit} - {base_unit}"
log.debug(msg)

Expand Down

0 comments on commit 9d45757

Please sign in to comment.