From 98e9a30477432b7ab4e721b9e54349bd65216e3e Mon Sep 17 00:00:00 2001 From: Omesh37 Date: Sat, 4 Jul 2026 22:40:52 +0530 Subject: [PATCH 1/2] 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/2] 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')