Skip to content

Fix OverflowError in the curve fitting dialog when a fitted value is outside the slider range - #77

Merged
PierreRaybaut merged 3 commits into
releasefrom
hotfix/fit-slider-overflow
Oct 28, 2026
Merged

PierreRaybaut merged 3 commits into
releasefrom
hotfix/fit-slider-overflow

Conversation

@PierreRaybaut

Copy link
Copy Markdown
Contributor

Fixes #76.

Problem

In the curve fitting dialog, FitParam.update_slider_value converted the parameter value into a slider position without clipping it. All automatic fit methods except L-BFGS-B are unconstrained. When one of them leaves a parameter far outside its [min, max] range, the position exceeds the 32-bit range of QSlider.setValue, which raises OverflowError. The slider is then left with its signals blocked, and the following parameters are not updated. Non-finite values, empty ranges (min == max), log scale values below min - 1, nan/inf typed in a field and a "Steps" value of 1 raised similar errors.

Changes (plotpy/widgets/fit.py)

  • The slider position is clipped to the slider range. It uses the exact inverse of the mapping of slider_value_changed (steps - 1), so the maximum value is the last slider position. Undefined positions (non-finite value, empty or infinite range) leave the slider unchanged.
  • The previous signal-blocking state of the slider is restored in a finally clause.
  • A value outside [min, max] is shown with a warning icon at the right of its field. The icon is the standard Qt one, so it works with any theme. Its tooltip (translated) gives the slider range. The value itself is never modified.
  • Non-numeric or non-finite values typed in a parameter field are rejected, and the previous value is restored.
  • The parameter properties dialog requires at least 2 slider steps.

Tests

  • New non-interactive tests in plotpy/tests/unit/test_fit_slider.py. 20 of them fail on the current code, with the same errors as reported in the issue, and all pass with the fix. They include a deterministic divergent automatic fit (linear model, fitted slope 1e6 times the slider range), independent of the SciPy version.
  • plotpy/tests/features/test_fit*.py pass. The full test suite passes, except test_curve_tools.py::test_edit_point_tool, which already fails on release without these changes.
  • The reproduction from the issue (Powell method, fit range on the tail of a Gaussian peak) now shows the warning icon with no error. Ruff passes, and Pylint reports no new message.

Workflow

Hotfix for 2.11.2, following doc/dev/gitworkflow.rst. The release branch was recreated from master (v2.11.1), and the fix will be cherry-picked into develop once merged.

… range

The slider position was computed without clipping, so a fitted value far
outside the [min, max] range of its parameter (unconstrained optimization
methods) exceeded the 32-bit range of QSlider.setValue: OverflowError, slider
signals left blocked and following parameters not updated. Non-finite values,
empty ranges and log scale values below min - 1 raised similar errors.

- Clip the slider position to the slider range, using the inverse mapping of
  slider_value_changed, and skip undefined positions
- Restore the slider signal-blocking state in a finally clause
- Show a warning icon with a tooltip when the value is outside the range
- Reject non-finite values typed in the parameter field
- Require at least 2 slider steps in the parameter properties dialog

Fixes #76

Assisted-by: Claude Opus 5.5
Python 3.9 is no longer available on the Ubuntu 26.04 image used by
ubuntu-latest, so the 3.9 job failed while setting up Python. The 2.11.x
maintenance line still supports Python 3.9.

Assisted-by: Claude Opus 5.5
@PierreRaybaut
PierreRaybaut merged commit 12c9f5d into release Oct 28, 2026
4 checks passed
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