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

FIX: fix is_integer() bug for QRules v0.10.4 #450

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
11e8c1c
fixed is_integer-not-implemented bug for Python < 3.12
grayson-helmholz Jan 17, 2025
16eefa3
MAINT: implement updates from pre-commit hooks
web-flow Jan 17, 2025
775f1a6
MAINT: update lock files
web-flow Jan 17, 2025
c092fbb
removed dispatching for `float`
grayson-helmholz Jan 17, 2025
f3f7eea
Merge branch 'hotfix_fraction_is_integer_bug' of github.com:ComPWA/am…
grayson-helmholz Jan 17, 2025
db5d490
removed redundant import
grayson-helmholz Jan 17, 2025
8e5c0df
mock-test for channel
grayson-helmholz Jan 17, 2025
00f3ecc
reintroduced dispatching on spin-type to support qrules 0.9
grayson-helmholz Jan 17, 2025
0568b80
removed OS-check
grayson-helmholz Jan 17, 2025
f3def7f
MAINT: update lock files
web-flow Jan 17, 2025
4503777
renamed inner function
grayson-helmholz Jan 17, 2025
a0bcd6b
Merge branch 'hotfix_fraction_is_integer_bug' of github.com:ComPWA/am…
grayson-helmholz Jan 17, 2025
242bb78
MAINT: remove `pygments` constraint
redeboer Jan 16, 2025
523b5a5
MAINT: remove `pytest-profiling` constraint
redeboer Jan 16, 2025
deaaf78
DX: remove `setuptools-scm` version configuration
redeboer Jan 17, 2025
68d35af
MAINT: update lock files
web-flow Jan 17, 2025
6f6431c
MAINT: update lock files
redeboer Jan 22, 2025
b3e066b
MAINT: update developer environment
redeboer Jan 22, 2025
b216928
DX: run tests in `tox` on all Python versions
redeboer Jan 22, 2025
9aa5d87
FIX: use union syntax for Python 3.9
redeboer Jan 22, 2025
9b84bf5
FIX: update expected hashses for different Python versions
redeboer Jan 22, 2025
60cb60f
MAINT: test framework on Python 3.13
redeboer Jan 22, 2025
8ce23b4
DX: test package on Python 3.13
redeboer Jan 22, 2025
6f089ce
FIX: install `tox-uv` on RTD
redeboer Jan 22, 2025
5fc8ae2
MAINT: remove redundant channel test
redeboer Jan 22, 2025
e48212b
REVERT: change back to `CI` variable for hash
redeboer Jan 22, 2025
2901494
FIX: mark macos also as CI
redeboer Jan 22, 2025
dc37759
MAINT: update lock files
web-flow Jan 22, 2025
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
13 changes: 7 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
- id: check-useless-excludes

- repo: https://github.com/ComPWA/policy
rev: 0.5.15
rev: 0.5.18
hooks:
- id: check-dev-files
args:
Expand All @@ -30,6 +30,7 @@ repos:
- --add-install-cell
- --additional-packages=IPython
- --extras-require=doc,viz
- id: set-nb-display-name

- repo: https://github.com/kynan/nbstripout
rev: 0.8.1
Expand Down Expand Up @@ -60,7 +61,7 @@ repos:
metadata.vscode

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.1
rev: v0.9.2
hooks:
- id: ruff
args: [--fix]
Expand Down Expand Up @@ -127,12 +128,12 @@ repos:
pass_filenames: false

- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.17.0
rev: v8.17.1
hooks:
- id: cspell

- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 3.0.3
rev: 3.1.2
hooks:
- id: editorconfig-checker
name: editorconfig
Expand All @@ -153,11 +154,11 @@ repos:
- python

- repo: https://github.com/ComPWA/pyright-pre-commit
rev: v1.1.391
rev: v1.1.392
hooks:
- id: pyright

- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.5.18
rev: 0.5.22
hooks:
- id: uv-lock
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ build:
uv run \
--group doc \
--no-dev \
--with tox \
--with tox-uv \
tox -e doc
mkdir -p $READTHEDOCS_OUTPUT
mv docs/_build/html $READTHEDOCS_OUTPUT
Expand Down
51 changes: 36 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python",
"Topic :: Scientific/Engineering :: Physics",
Expand Down Expand Up @@ -141,10 +142,13 @@ namespaces = false
where = ["src"]

[tool.setuptools_scm]
local_scheme = "no-local-version"
version_scheme = "only-version"
write_to = "src/ampform/version.py"

[tool.coverage.report]
exclude_also = [
"if TYPE_CHECKING:",
]

[tool.coverage.run]
branch = true
source = ["src"]
Expand Down Expand Up @@ -436,6 +440,11 @@ trailing_comma_inline_array = true

[tool.tox]
env_list = [
"3.9",
"3.10",
"3.11",
"3.12",
"3.13",
"bench",
"cov",
"docnb-force",
Expand All @@ -448,13 +457,16 @@ skip_install = true
skip_missing_interpreters = true

[tool.tox.env_run_base]
allowlist_externals = ["pytest"]
commands = [["pytest", {replace = "posargs", extend = true}]]
description = "Run all unit tests"
dependency_groups = ["test"]
description = "Run test suite on Python {env_name}"
no_package = false
pass_env = ["*"]
runner = "uv-venv-lock-runner"
skip_install = false
skip_missing_interpreters = false

[tool.tox.env.bench]
allowlist_externals = ["pytest"]
commands = [
[
"pytest",
Expand All @@ -468,7 +480,6 @@ commands = [
description = "Run benchmark tests and visualize in histogram"

[tool.tox.env.cov]
allowlist_externals = ["pytest"]
commands = [
[
"pytest",
Expand All @@ -483,6 +494,7 @@ description = "Compute test coverage"

[tool.tox.env.doc]
allowlist_externals = ["sphinx-build"]
base = []
commands = [
[
"sphinx-build",
Expand All @@ -499,6 +511,7 @@ set_env.PYTHONWARNINGS = ""

[tool.tox.env.doclive]
allowlist_externals = ["sphinx-autobuild"]
base = []
commands = [
[
"sphinx-autobuild",
Expand Down Expand Up @@ -531,31 +544,31 @@ commands = [
description = "Set up a server to directly preview changes to the HTML pages"

[tool.tox.env.docnb]
base = ["tool.tox.env.doc", "tool.tox.env_run_base"]
base = ["tool.tox.env.doc"]
description = "{[tool.tox.env.doc]description} with cached notebook execution"
set_env = [
{replace = "ref", of = ["tool.tox.env.doc.set_env"]},
{EXECUTE_NB = "yes"},
]

[tool.tox.env.docnb-force]
base = ["tool.tox.env.doc", "tool.tox.env_run_base"]
base = ["tool.tox.env.doc"]
description = "{[tool.tox.env.doc]description} with notebook execution (no cache)"
set_env = [
{replace = "ref", of = ["tool.tox.env.doc.set_env"]},
{FORCE_EXECUTE_NB = "yes"},
]

[tool.tox.env.docnblive]
base = ["tool.tox.env.doclive", "tool.tox.env_run_base"]
base = ["tool.tox.env.doclive"]
description = "{[tool.tox.env.doclive]description} with cached notebook execution"
set_env = [
{replace = "ref", of = ["tool.tox.env.doclive.set_env"]},
{EXECUTE_NB = "yes"},
]

[tool.tox.env.linkcheck]
allowlist_externals = ["sphinx-build"]
base = ["tool.tox.env.doc"]
commands = [
[
"sphinx-build",
Expand All @@ -569,17 +582,25 @@ description = "Check external links in the documentation (requires internet conn

[tool.tox.env.nb]
allowlist_externals = ["pytest"]
base = []
commands = [["pytest", "--nbmake", "{posargs:docs}"]]
description = "Run all notebooks with pytest"

[tool.tox.env.sty]
allowlist_externals = ["pre-commit"]
base = []
commands = [["pre-commit", "run", "--all-files", {replace = "posargs", extend = true}]]
description = "Perform all linting, formatting, and spelling checks"

[tool.uv]
constraint-dependencies = [
"pygments!=2.19.*", # https://github.com/felix-hilden/sphinx-codeautolink/issues/152
"pytest-profiling!=1.8.0",
"sphinx-codeautolink!=0.16.0",
[tool.tox.labels]
doc = [
"docnb-force",
"linkcheck",
]
test = [
"3.9",
"3.10",
"3.11",
"3.12",
"3.13",
]
11 changes: 10 additions & 1 deletion src/ampform/helicity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import sys
import warnings
from collections import OrderedDict, abc
from fractions import Fraction
from functools import reduce, singledispatchmethod
from typing import TYPE_CHECKING, Union

Expand Down Expand Up @@ -928,13 +929,21 @@
def _generate_kinematic_variable_set(
transition: StateTransition, node_id: int
) -> TwoBodyKinematicVariableSet:
def is_integer(spin: float | Fraction) -> bool:
if isinstance(spin, float):
return spin.is_integer()

Check warning on line 934 in src/ampform/helicity/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/ampform/helicity/__init__.py#L934

Added line #L934 was not covered by tests
if isinstance(spin, Fraction):
return spin.denominator == 1
msg = "spin has to of type float (qrules 0.9) or Fraction (qrules >= 0.10)"
raise TypeError(msg)

Check warning on line 938 in src/ampform/helicity/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/ampform/helicity/__init__.py#L937-L938

Added lines #L937 - L938 were not covered by tests

decay = TwoBodyDecay.from_transition(transition, node_id)
inv_mass, phi, theta = _generate_kinematic_variables(transition, node_id)
topology = transition.topology
child1_mass = get_invariant_mass_symbol(topology, decay.children[0].id)
child2_mass = get_invariant_mass_symbol(topology, decay.children[1].id)
angular_momentum: int | None = decay.interaction.l_magnitude
if angular_momentum is None and decay.parent.particle.spin.is_integer():
if angular_momentum is None and is_integer(decay.parent.particle.spin):
angular_momentum = int(decay.parent.particle.spin)
return TwoBodyKinematicVariableSet(
incoming_state_mass=inv_mass,
Expand Down
2 changes: 1 addition & 1 deletion src/ampform/sympy/_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ def get_readable_hash(obj) -> str:


def to_bytes(obj) -> bytes:
if isinstance(obj, bytes | bytearray):
if isinstance(obj, (bytes, bytearray)):
return obj
return pickle.dumps(obj, protocol=pickle.HIGHEST_PROTOCOL)
13 changes: 10 additions & 3 deletions tests/sympy/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import os
import sys
from typing import TYPE_CHECKING, ClassVar

import pytest
Expand All @@ -18,7 +19,7 @@
from qrules.transition import SpinFormalism


_GH = "CI" in os.environ and os.uname().sysname != "Darwin"
_GH = "CI" in os.environ


@pytest.mark.parametrize(
Expand Down Expand Up @@ -66,8 +67,14 @@ class TestLargeHash:
@pytest.mark.parametrize(
("expected_hash", "formalism"),
[
("762cc00", "canonical-helicity"),
("17fefe5", "helicity"),
(
"762cc00" if sys.version_info >= (3, 11) else "1f5ac33",
"canonical-helicity",
),
(
"17fefe5" if sys.version_info >= (3, 11) else "7b5fad1",
"helicity",
),
],
ids=["canonical-helicity", "helicity"],
)
Expand Down
Loading