Skip to content

BUG: fix divide by zero in quartic_restricted when y is constant GH#234#235

Open
Omesh37 wants to merge 2 commits into
pvlib:mainfrom
Omesh37:fix/rsquared-divide-by-zero
Open

BUG: fix divide by zero in quartic_restricted when y is constant GH#234#235
Omesh37 wants to merge 2 commits into
pvlib:mainfrom
Omesh37:fix/rsquared-divide-by-zero

Conversation

@Omesh37

@Omesh37 Omesh37 commented Jul 4, 2026

Copy link
Copy Markdown

Description

pvanalytics/util/_fit.py raised RuntimeWarning: divide by zero encountered in scalar divide when y contains constant values.

In quartic_restricted, the R² denominator np.sum((y - np.mean(y))**2) evaluates to zero when all values in y are identical. This caused a RuntimeWarning in:

  • test_orientation.py::test_ghi_not_tracking
  • test_orientation.py::test_power_tracking_perturbed

Fix: Check if ss_tot == 0 before dividing. If so, return 0.0 since R² is undefined for constant data (no variation to explain).

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.

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

1 participant