Skip to content

Commit a3cab42

Browse files
yearsets.sample_events: improve error message in case
events for one year > events at all
1 parent 42816d2 commit a3cab42

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

climada/util/yearsets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ def sample_events(events_per_year, freqs_orig):
199199

200200
#sample events for each sampled year
201201
for amount_events in events_per_year:
202+
#if there are not enough input events, choice with no replace will fail
203+
if amount_events > len(freqs_orig):
204+
raise ValueError(f"cannot sample {amount_events} distinct events for a single year"
205+
f" when there are only {len(freqs_orig)} input events")
202206

203207
#add the original indices and frequencies to the pool if there are less events
204208
#in the pool than needed to fill the year one is sampling for

0 commit comments

Comments
 (0)