From 98e9a30477432b7ab4e721b9e54349bd65216e3e Mon Sep 17 00:00:00 2001 From: Omesh37 Date: Sat, 4 Jul 2026 22:40:52 +0530 Subject: [PATCH 1/4] BUG: fix divide by zero in quartic_restricted when y is constant GH#234 --- pvanalytics/util/_fit.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pvanalytics/util/_fit.py b/pvanalytics/util/_fit.py index 65a61559..eb33f2a2 100644 --- a/pvanalytics/util/_fit.py +++ b/pvanalytics/util/_fit.py @@ -127,4 +127,8 @@ def _quartic(x, a, b, c, e): ) model = _quartic(x, params[0], params[1], params[2], params[3]) residuals = y - model - return 1 - (np.sum(residuals**2) / np.sum((y - np.mean(y))**2)) + ss_res = np.sum(residuals**2) + ss_tot = np.sum((y - np.mean(y))**2) + if ss_tot == 0: + return 0.0 + return 1 - (ss_res / ss_tot) From c7065d9831dbfaaab9708140b73586efcb20aa77 Mon Sep 17 00:00:00 2001 From: Omesh37 Date: Sun, 5 Jul 2026 20:46:43 +0530 Subject: [PATCH 2/4] Fix of error related to converting to timedelta --- pvanalytics/util/_functions.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pvanalytics/util/_functions.py b/pvanalytics/util/_functions.py index 455dde35..90e2cebe 100644 --- a/pvanalytics/util/_functions.py +++ b/pvanalytics/util/_functions.py @@ -14,5 +14,11 @@ def freq_to_timedelta(freq): ------- Timedelta Timedelta corresponding to a single period at `freq`. + For offsets that cannot be directly converted (e.g. 'D', 'W'), + falls back to using the offset's nanosecond representation. """ - return pd.to_timedelta(frequencies.to_offset(freq)) + offset = frequencies.to_offset(freq) + try: + return pd.to_timedelta(offset) + except ValueError: + return pd.Timedelta(offset.nanos, unit='ns') From 6b1546d831d718a32be6129b8fa81dedf9148e7b Mon Sep 17 00:00:00 2001 From: Omesh37 Date: Mon, 6 Jul 2026 21:35:48 +0530 Subject: [PATCH 3/4] REVERT: remove timedelta fix from wrong PR, will be addressed separately --- pvanalytics/util/_functions.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pvanalytics/util/_functions.py b/pvanalytics/util/_functions.py index 90e2cebe..455dde35 100644 --- a/pvanalytics/util/_functions.py +++ b/pvanalytics/util/_functions.py @@ -14,11 +14,5 @@ def freq_to_timedelta(freq): ------- Timedelta Timedelta corresponding to a single period at `freq`. - For offsets that cannot be directly converted (e.g. 'D', 'W'), - falls back to using the offset's nanosecond representation. """ - offset = frequencies.to_offset(freq) - try: - return pd.to_timedelta(offset) - except ValueError: - return pd.Timedelta(offset.nanos, unit='ns') + return pd.to_timedelta(frequencies.to_offset(freq)) From 0d1b143cf00ea4360b1a39f2a475cc08d757c11e Mon Sep 17 00:00:00 2001 From: Omesh37 Date: Sat, 11 Jul 2026 22:46:04 +0530 Subject: [PATCH 4/4] Fix divide-by-zero RuntimeWarning in quartic_restricted_r2 when y is constant --- pvanalytics/util/_fit.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pvanalytics/util/_fit.py b/pvanalytics/util/_fit.py index eb33f2a2..479be44a 100644 --- a/pvanalytics/util/_fit.py +++ b/pvanalytics/util/_fit.py @@ -127,8 +127,7 @@ def _quartic(x, a, b, c, e): ) model = _quartic(x, params[0], params[1], params[2], params[3]) residuals = y - model - ss_res = np.sum(residuals**2) ss_tot = np.sum((y - np.mean(y))**2) if ss_tot == 0: - return 0.0 - return 1 - (ss_res / ss_tot) + return 0.0 + return 1 - (np.sum(residuals**2) / ss_tot)