Skip to content

fix(plot): PyPlot and PyPlot2 step() raise ValueError for a dt of zero or less - #875

Merged
petercorke merged 6 commits into
mainfrom
fix/pyplot-step-zero-dt
Oct 21, 2026
Merged

petercorke merged 6 commits into
mainfrom
fix/pyplot-step-zero-dt

Conversation

@petercorke

@petercorke petercorke commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

PyPlot.step(0) and PyPlot2.step(0) hung with no message: step ends with plt.pause(dt), and Matplotlib's pause(0) does not return, because a timeout of zero means "wait until the event loop is stopped". Found while writing tests for #873.

Both step methods now raise ValueError("dt is 0, it must be greater than zero: ...") for a dt of zero or less in the window render mode, which is the only mode that calls plt.pause; in a notebook there is no pause and dt=0 is fine (the notebook animation tests pass dt=0.0, which the first version of this PR broke on CI). Documented in the docstring. robot.plot(q, dt=0) raises the same way (after the scene is made). Swift is not affected and its step(0) is unchanged; the one example that calls env.step(0) (examples/mexican-wave.py) uses Swift.

Not changed: other plt.pause calls that take a caller's value; they are listed in #876 (PoseGraph.plot_scan(pause=0) and the Vehicle animation).

Changes public behaviour: a zero or negative dt raised nothing and never returned; it now raises ValueError. No change to anything that worked.

Ran: the full test suite (all pass except the 20 known test_servo_half_turn failures from a stale compiled extension in my worktree) and mypy (clean, 165 files); the real-kernel notebook tests (test_notebook_animation.py, test_swift_notebook.py) against this branch's code, by a kernelspec that imports the worktree, since the default kernel imports the editable install. New tests/test_step_dt.py (14 tests, each with a timeout so that a regression fails instead of hanging).

Written with Claude Code.

🤖 Generated with Claude Code

…o or less

plt.pause(0) does not return, because a timeout of zero means to wait until the
event loop is stopped, so env.step(0) hung with no message.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@petercorke
petercorke enabled auto-merge (squash) October 21, 2026 07:05
@codacy-production

codacy-production Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 10 complexity · 0 duplication

Metric Results
Complexity 10
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

petercorke and others added 4 commits October 21, 2026 18:28
… an error

The notebook animation draws a frame for each step and does not pause, and its tests
(and users) pass dt=0.  Raising for every render mode broke them on CI.  The hang is
plt.pause(0), which is only called in the window render mode.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (649b8fb) to head (8c0a85f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/roboticstoolbox/backends/PyPlot/PyPlot.py 0.00% 2 Missing ⚠️
src/roboticstoolbox/backends/PyPlot/PyPlot2.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #875   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files        146     146           
  Lines      17096   17100    +4     
=====================================
- Misses     17096   17100    +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@petercorke
petercorke merged commit 934ca7d into main Oct 21, 2026
23 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 21, 2026
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