Skip to content

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

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

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

Conversation

@Omesh37

@Omesh37 Omesh37 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

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).

@Omesh37 Omesh37 marked this pull request as draft July 11, 2026 17:07
@Omesh37 Omesh37 marked this pull request as ready for review July 11, 2026 17:16
@Omesh37 Omesh37 changed the title BUG: fix divide by zero in quartic_restricted when y is constant GH#234 BUG: fix divide by zero in quartic_restricted when y is constant Jul 12, 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.

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

1 participant