Skip to content

Commit

Permalink
Remove Particle deprecated methods (#572)
Browse files Browse the repository at this point in the history
* Remove deprecated Particle methods

* Remove related and hence obsoleted tests

* Remove unnecessary src/particle/_compat/warnings.py

* style: pre-commit fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
eduardo-rodrigues and pre-commit-ci[bot] authored Feb 5, 2024
1 parent 7dc7558 commit a32e5f1
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 153 deletions.
10 changes: 0 additions & 10 deletions src/particle/_compat/warnings.py

This file was deleted.

99 changes: 0 additions & 99 deletions src/particle/particle/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@

from .. import data
from .._compat.typing import Traversable
from .._compat.warnings import deprecated
from ..converters.evtgen import EvtGenName2PDGIDBiMap
from ..pdgid import PDGID, is_valid
from ..pdgid.functions import Location, _digit
from ..typing import HasOpen, HasRead, StringOrIO
from .enums import (
Charge,
Charge_mapping,
Charge_undo,
Inv,
Parity,
Expand All @@ -35,7 +33,6 @@
Status,
)
from .kinematics import width_to_lifetime
from .regex import getname
from .utilities import latex_to_html_name, programmatic_name, str_with_unc

__all__ = ("Particle", "ParticleNotFound", "InvalidParticle")
Expand Down Expand Up @@ -1238,99 +1235,3 @@ def findall(
return list(
cls.finditer(filter_fn=filter_fn, particle=particle, **search_terms)
)

@classmethod
@deprecated(
"This method is deprecated and will be removed from version 0.23.0. Use finditer or findall instead.",
)
def from_string(cls: type[Self], name: str) -> Self:
"Get a particle from a PDG style name - returns the best match."
matches = cls.from_string_list(name)
if matches:
return matches[0]
raise ParticleNotFound(f"{name} not found in particle table")

@classmethod
@deprecated(
"This method is deprecated and will be removed from version 0.23.0. Use finditer or findall instead.",
)
def from_string_list(cls: type[Self], name: str) -> list[Self]:
"Get a list of particles from a PDG style name."

# Forcible override
particle = None

short_name = name
if "~" in name:
short_name = name.replace("~", "")
particle = False

# Try the simplest searches first
list_can = cls.findall(name=name, particle=particle)
if list_can:
return list_can
list_can = cls.findall(pdg_name=short_name, particle=particle)
if list_can:
return list_can

mat_str = getname.match(short_name)

if mat_str is None:
return []

mat = mat_str.groupdict()

if particle is False:
mat["bar"] = "bar"

try:
return cls._from_group_dict_list(mat)
except ParticleNotFound:
return []

@classmethod
def _from_group_dict_list(cls: type[Self], mat: dict[str, Any]) -> list[Self]:
kw: dict[str, Any] = {
"particle": False
if mat["bar"] is not None
else True
if mat["charge"] == "0"
else None
}

name = mat["name"]

if mat["family"]:
if "_" in mat["family"]:
mat["family"] = mat["family"].strip("_")
name += f'({mat["family"]})'
if mat["state"]:
name += f'({mat["state"]})'

if "prime" in mat and mat["prime"]:
name += "'"

if mat["star"]:
name += "*"

if mat["state"] is not None:
kw["J"] = float(mat["state"])

maxname = name + f'({mat["mass"]})' if mat["mass"] else name
if "charge" in mat and mat["charge"] is not None:
kw["three_charge"] = Charge_mapping[mat["charge"]]

vals = cls.findall(name=lambda x: maxname in x, **kw)
if not vals:
vals = cls.findall(name=lambda x: name in x, **kw)

if not vals:
raise ParticleNotFound(f"Could not find particle {maxname} or {name}")

if len(vals) > 1 and mat["mass"] is not None:
vals = [val for val in vals if mat["mass"] in val.latex_name]

if len(vals) > 1:
return sorted(vals)

return vals
44 changes: 0 additions & 44 deletions tests/particle/test_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,25 +220,6 @@ def test_int_compare():
assert Particle.from_pdgid(-211) <= 0


def test_string():
with pytest.deprecated_call():
pi = Particle.from_string("pi+")
assert pi.pdgid == 211

with pytest.raises(ParticleNotFound), pytest.deprecated_call():
Particle.from_string("unknown")


def test_fuzzy_string():
"""
The input name is not specific enough, in which case the search is done
by pdg_name after failing a match by name.
"""
with pytest.deprecated_call():
p = Particle.from_string("a(0)(980)") # all 3 charge stages match
assert p.pdgid == 9000111


def test_str():
pi = Particle.from_pdgid(211)
assert str(pi) == "pi+"
Expand Down Expand Up @@ -660,31 +641,6 @@ def test_to_dict():
assert set(query_as_dict["name"]) == {"e+", "mu+", "tau+", "tau'+"}


ampgen_style_names = (
("b", 5),
("b~", -5),
("pi+", 211),
("pi-", -211),
("K~*0", -313),
("K*(892)bar0", -313),
("a(1)(1260)+", 20213),
("rho(1450)0", 100113),
("rho(770)0", 113),
("K(1)(1270)bar-", -10323),
# ("K(1460)bar-", -100321),
("K(2)*(1430)bar-", -325),
)


@pytest.mark.parametrize(("name", "pid"), ampgen_style_names)
def test_ampgen_style_names(name, pid):
with pytest.deprecated_call():
particle = Particle.from_string(name)

assert particle.pdgid == pid
assert particle == pid


decfile_style_names = (
("s", 3),
("anti-b", -5),
Expand Down

0 comments on commit a32e5f1

Please sign in to comment.