Skip to content

QRules fails with particle v1 charge fractions #334

Description

@redeboer

particle v1 changed the type of charge values from float to fractions.Fraction. QRules currently assumes that item.charge behaves like a float and calls item.charge.is_integer() while loading the PDG particle definitions.

and item.charge.is_integer() # remove quarks

Also, the spin J of the particle is now sometimes None, which is a problem here:

spin=float(pdg_particle.J),

This came up while updating the dependency lock file to particle v1 in #333.

How to reproduce?

Use Python 3.10 for the reproducer, because newer Python versions can mask this via Fraction.is_integer().

This works on main with particle==0.26.2:

uv run --python 3.10 --with particle==0.26.2 python - <<'PY'
from importlib.metadata import version
from qrules.particle import load_pdg

print(f"particle {version('particle')}")
print(len(load_pdg()))
PY

Expected output:

particle 0.26.2
541

This crashes on main with particle==1.0.0:

uv run --python 3.10 --with particle==1.0.0 python - <<'PY'
from importlib.metadata import version
from qrules.particle import load_pdg

print(f"particle {version('particle')}")
print(len(load_pdg()))
PY

Expected failure:

particle 1.0.0
AttributeError: 'Fraction' object has no attribute 'is_integer'

Metadata

Metadata

Assignees

Labels

🐛 BugSomething isn't working

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions