Skip to content

BUG: divide by zero RuntimeWarning in _fit.quartic_restricted when y is constant #234

Description

@Omesh37

Bug description

pvanalytics/util/_fit.py raises a error: RuntimeWarning: divide by zero encountered in scalar divide when y contains constant values, because the R² denominator np.sum((y - np.mean(y))**2) evaluates to zero.

To reproduce

import numpy as np
from pvanalytics.util import _fit

x = np.arange(10)
y = pd.Series(np.ones(10) * 5.0)  # constant y
_fit.quartic_restricted(x, y)  # RuntimeWarning here

Traceback

RuntimeWarning: divide by zero encountered in scalar divide pvanalytics/util/_fit.py:130

Expected behavior

Returns 0.0 (undefined R², treated as worst-case fit) without warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions