Skip to content

Curve fitting: OverflowError when a fitted value is far outside the parameter slider range #76

Closed

Description

@PierreRaybaut

Describe the bug

In the curve fitting dialog (plotpy.widgets.fit), running the automatic fit may raise an unhandled exception when a fitted parameter value ends up far outside the [min, max] range of its slider:

Traceback (most recent call last):
  File "plotpy/widgets/fit.py", line 749, in autofit
    prm.update()
  File "plotpy/widgets/fit.py", line 354, in update
    self.update_slider_value()
  File "plotpy/widgets/fit.py", line 328, in update_slider_value
    self.slider.setValue(intval)
OverflowError: argument 1 overflowed: value must be in the range -2147483648 to 2147483647

Besides the error message, the dialog is left in an inconsistent state:

  • the slider of the faulty parameter stays unresponsive: the exception is raised between blockSignals(True) and blockSignals(False), so moving the slider no longer changes the value;
  • the fields of the parameters following the faulty one are not updated, while the fit curve already shows the new values.

To Reproduce

  1. Open a fit dialog on a Gaussian peak (e.g. y = 5 exp(-x²/2) on [-10, 10], with parameters ranges of a few units)
  2. Click "Bounds" and restrict the fit range to the tail of the peak, e.g. [8, 10]
  3. In "Settings", choose the Powell method
  4. Click "Run"
  5. The amplitude diverges and the exception above is raised (the computed slider position is about 1e14)

Only L-BFGS-B uses the [min, max] bounds of the parameters: the other methods (including the default least squares method) are unconstrained, so any ill-posed fit may move a parameter far away from its slider range.

Expected behavior

The fit result is displayed without error: the slider stays at the nearest end of its range, remains usable, and all parameter fields show the fitted values. A value outside the slider range should be visible as such.

Additional context

The cause is in FitParam.update_slider_value, which converts the value into a slider position without clipping it to the slider range:

intval = int(self.steps * value_delta / total_delta)
self.slider.setValue(intval)

With steps = 5000, a value about 430 000 times the range width away from min exceeds the 32-bit range of QSlider.setValue. The same code path fails in other situations:

  • min == max and a different value: division by zero, then OverflowError: cannot convert float infinity to integer (or ZeroDivisionError when the dialog is created)
  • log scale with a value below min - 1: ValueError: cannot convert float NaN to integer
  • nan or inf typed in a parameter field: accepted as values, then ValueError/OverflowError
  • a "Steps" value of 1 in the parameter properties dialog: ZeroDivisionError when the slider is moved

Activity

  1. added a commit that references this issue on Oct 28, 2026
    42d5da4
  2. PierreRaybaut commented on Oct 28, 2026

    @PierreRaybaut
    ContributorAuthor

    Fixed in 2.11.2 by #77 (merged into release), and cherry-picked into develop (42d5da4, 42451a3).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions