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

Remove misleading/awkward/unexpected Particle.__int__ method #265

Merged
merged 5 commits into from
Sep 10, 2020
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
11 changes: 1 addition & 10 deletions notebooks/ParticleDemo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@
"metadata": {},
"outputs": [],
"source": [
"[int(p) for p in all_particles]"
"[int(p.pdgid) for p in all_particles]"
]
},
{
Expand Down Expand Up @@ -620,15 +620,6 @@
"p.pdgid"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"PDGID(p)"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down
13 changes: 4 additions & 9 deletions src/particle/particle/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,11 @@ def __le__(self, other):
# Sort by absolute particle numbers
# The positive one should come first
if type(self) == type(other):
return abs(int(self) - 0.25) < abs(int(other) - 0.25)
return abs(int(self.pdgid) - 0.25) < abs(int(other.pdgid) - 0.25)

# Comparison with anything else should produce normal comparisons.
else:
return int(self) < other
return int(self.pdgid) < other

def __eq__(self, other):
# type: (Any) -> bool
Expand All @@ -608,11 +608,6 @@ def __hash__(self):
# type: () -> int
return hash(self.pdgid)

# Integer == PDGID
def __int__(self):
# type: () -> int
return int(self.pdgid)

# Shared with PDGID

@property
Expand Down Expand Up @@ -1043,9 +1038,9 @@ def findall(

# particle=True is particle, False is antiparticle, and None is both
if particle is not None:
if particle and int(item) < 0:
if particle and int(item.pdgid) < 0:
continue
elif (not particle) and int(item) > 0:
elif (not particle) and int(item.pdgid) > 0:
continue

# If a filter function is passed, evaluate and skip if False
Expand Down
5 changes: 2 additions & 3 deletions tests/particle/test_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def test_pdg():
def test_pdg_convert():
p = Particle.from_pdgid(211)
assert isinstance(p.pdgid, PDGID)
assert int(p) == 211
assert PDGID(p) == 211
assert p.pdgid == 211
assert int(p.pdgid) == 211


def test_sorting():
Expand Down Expand Up @@ -576,7 +576,6 @@ def test_to_list():
def test_ampgen_style_names(name, pid):
particle = Particle.from_string(name)

assert int(particle) == pid
assert particle.pdgid == pid
assert particle == pid

Expand Down