Skip to content

docs: share BinnedData across plots, the beta relation, plot-block guards - #529

Merged
blalterman merged 5 commits into
masterfrom
docs/binned-data-and-followups
Nov 5, 2026
Merged

blalterman merged 5 commits into
masterfrom
docs/binned-data-and-followups

Conversation

@blalterman

Copy link
Copy Markdown
Owner

Docs follow-ups for v0.4.1, so the "stable" docs include them.

  • Usage guide: share one BinnedData across several plots, with a measured time and memory comparison (setup stated).
  • Quickstart: the plasma beta relation each column uses, beta = n k_B T / (B^2/2 mu_0) = 2 mu_0 p_th / B^2.
  • README: the pre-commit hook list points to .pre-commit-config.yaml.
  • tests/test_docs_plot_blocks.py: an empty .. plot:: block or one with a file argument fails with its file and line.

Docs and tests only; the package code is unchanged.

🤖 Generated with Claude Code

blalterman and others added 5 commits November 5, 2026 04:06
An empty .. plot:: block now fails with its file and line rather than a
ValueError from min(), and a block that names a script (.. plot:: x.py)
fails, since the guide keeps every figure's code inline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
beta = n k_B T / (B^2 / 2 mu_0) = 2 mu_0 p_th / B^2, with p_th = rho w^2 / 2
from the component's thermal speed, as Plasma.beta computes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A section after Bins builds one BinnedData and passes it to a count
histogram, a mean-z histogram and a masked one, with a two-panel figure.
It states the time and memory saved as measured: ten Hist2D of different
z on 10^6 points, 0.28 s and 3 MB retained shared against 0.57 s and
21 MB private (Apple M3, median of three, tracemalloc).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Claude finished @blalterman's task in 23s —— View job


Review of PR #529

I read the diff only. I did not build the docs or run the tests or doctests.

Overall: This is a clean docs and tests change with no package code touched. I found nothing blocking.

tests/test_docs_plot_blocks.py

  • The regex change from \s*$ to (.*)$ is what lets the guard see .. plot:: script.py. The old pattern skipped those blocks without a sound. The min(..., default=0) fix and the early assert code are correct for an empty block.
  • In yield i + 1, match.group(2).strip(), code + "\n" if code else "", the conditional binds only to the third element, so it does what you intend. Parentheses would make that clear to a reader.
  • test_every_plot_block_holds_its_code_inline and the empty-block assertion both report file and line, as the PR says.
  • Per CLAUDE.md, changes are test-first with a strict=True xfail landing before the fix. Here the guards and the docs land together. The guards pass on the current docs, so this is probably acceptable. No test shows the guards fail on a bad block, though. A small test that runs the checker on a temporary .rst with an empty block and one with a file argument would prove they fire.

docs/source/usage.rst

  • The doctest pins (10000, 6947). It is deterministic with default_rng(0), so it is a reasonable guard. It rests on NumPy's Generator stream staying stable, and it has no independent source. You could assert a relation instead, for example that the masked sum equals int((frame["v"] < 500).sum()). That holds as long as all points fall inside the edges. With v in 0–1000 and n in 10^-1 to 10^2.5, some points may fall outside the n edges, so check this before switching.
  • The benchmark figures (0.28 s vs 0.57 s, 3 MB vs 21 MB, 60 MB vs 79 MB) have no script in the repo, so a reader cannot reproduce them. The setup is stated, which helps. Consider linking or committing the benchmark script, or hedging that the numbers vary by machine.
  • The text says the plot "neither bins nor stores its own", and then that a plot "finds its columns by the names of its inputs". The second statement is easy to miss and likely to trip users whose Series are unnamed. A one-line example of the failure would help.
  • The .. plot:: block repeats the data generation from the doctest. That is a second copy, which CLAUDE.md says to extract. In docs a self-contained block is justified, because the new test runs each block alone, so it is acceptable.

docs/source/tutorial/quickstart.rst

  • The physics is correct. With w² = 2k_BT/m, ρw²/2 = n k_B T, and so β = 2μ₀p_th/B². The text cites the relation and the units. This is a standard result, so no citation is needed. If you want one, add a textbook reference.

README.rst

  • Pointing to .pre-commit-config.yaml as the single source avoids drift. The rewrite also drops the coverage-floor and import-test details, which is fine.

CHANGELOG.md

  • The Usage entry is there. The quickstart beta relation, the README change, and the new test guards are not listed. Add them if you track docs and tests in the changelog.

Summary: Approve, with optional suggestions: a test that shows the guards fire, a relation in place of the pinned 6947, and a reproducible benchmark script.

@blalterman
blalterman merged commit 4e5685a into master Nov 5, 2026
11 checks passed
@blalterman blalterman mentioned this pull request Nov 5, 2026
16 tasks
@blalterman
blalterman deleted the docs/binned-data-and-followups branch November 5, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant