Skip to content

Commit d9e48d0

Browse files
authored
FIX: shift Markdown row for Particles (#174)
1 parent 92bf066 commit d9e48d0

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/ampform_dpd/io/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ def _as_resonance_markdown_table(items: Sequence[Particle | State]) -> str:
173173
f"{int(1e3 * particle.mass):,.0f}",
174174
f"{int(1e3 * particle.width):,.0f}",
175175
]
176-
if render_index and isinstance(particle, State):
177-
row_items.insert(0, particle.index)
176+
if render_index:
177+
row_items.insert(0, particle.index if isinstance(particle, State) else " ")
178178
src += _create_markdown_table_row(row_items)
179179
return src
180180

tests/test_io.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# pyright: reportPrivateUsage=false
22
from __future__ import annotations
33

4-
from ampform_dpd.decay import IsobarNode, Particle
5-
from ampform_dpd.io import aslatex
4+
from textwrap import dedent
5+
6+
from attrs import asdict
7+
8+
from ampform_dpd.decay import IsobarNode, Particle, State
9+
from ampform_dpd.io import as_markdown_table, aslatex
610

711
# https://compwa-org--129.org.readthedocs.build/report/018.html#resonances-and-ls-scheme
812
dummy_args = {"mass": 0, "width": 0}
@@ -35,3 +39,18 @@ def test_aslatex_isobar_node():
3539
node = IsobarNode(Λ1520, p, K, interaction=(2, 1))
3640
latex = aslatex(node)
3741
assert latex == R"\left(\Lambda(1520) \xrightarrow[S=1]{L=2} p K^-\right)"
42+
43+
44+
def test_as_markdown_table_particles():
45+
p_state = State(**asdict(p), index=1)
46+
k_state = State(**asdict(K), index=2)
47+
particles = [p_state, k_state, π]
48+
src = as_markdown_table(particles)
49+
expected = dedent(R"""
50+
| index | name | LaTeX | $J^P$ | mass (MeV) | width (MeV) |
51+
| --- | --- | --- | --- | --- | --- |
52+
| 1 | `p` | $p$ | $\frac{1}{2}^+$ | 0 | 0 |
53+
| 2 | `K-` | $K^-$ | $0^-$ | 0 | 0 |
54+
| | `π+` | $\pi^+$ | $0^-$ | 0 | 0 |
55+
""")
56+
assert src.strip() == expected.strip()

0 commit comments

Comments
 (0)