Skip to content

Commit 3f773bf

Browse files
Copilotcdeline
andauthored
Fix broad except ValueError in degradation_timeseries_plot for multi-YoY detection (#490)
* Initial plan * Replace broad except ValueError with explicit duplicate-index check in degradation_timeseries_plot Co-authored-by: cdeline <23244088+cdeline@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: cdeline <23244088+cdeline@users.noreply.github.com>
1 parent 1d2d060 commit 3f773bf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

rdtools/plotting.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,8 @@ def _bootstrap(x, percentile, reps):
487487
if ci_color is None:
488488
ci_color = 'C0'
489489

490-
try:
491-
roller = results_values.rolling(f'{rolling_days}d', min_periods=rolling_days//4,
492-
center=True)
493-
except ValueError:
490+
results_values = results_values.sort_index()
491+
if results_values.index.has_duplicates:
494492
# this occurs with degradation_year_on_year(multi_yoy=True). resample to daily mean
495493
warnings.warn(
496494
"Input `yoy_info['YoY_values']` appears to have multiple annual "
@@ -503,6 +501,9 @@ def _bootstrap(x, percentile, reps):
503501
roller = results_values.resample('D').mean().rolling(f'{rolling_days}d',
504502
min_periods=rolling_days//4,
505503
center=True)
504+
else:
505+
roller = results_values.rolling(f'{rolling_days}d', min_periods=rolling_days//4,
506+
center=True)
506507
# unfortunately it seems that you can't return multiple values in the rolling.apply() kernel.
507508
# TODO: figure out some workaround to return both percentiles in a single pass
508509
if include_ci:

0 commit comments

Comments
 (0)