Skip to content

Commit 524472d

Browse files
committed
Amend random_year tests to avoid ValueError: No cohorts available
1 parent 19e5efc commit 524472d

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

tests/anoph/test_snp_frq.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ def add_random_year(*, api):
123123
# Only create the new column if it doesn't already exist.
124124
# Otherwise we'll get multiple columns with different suffixes, e.g. 'random_year_x' and 'random_year_y'.
125125
if "random_year" not in sample_metadata_df.columns:
126-
random_years_as_list = np.random.choice(
127-
range(1900, 2100), len(sample_metadata_df)
128-
)
126+
# Avoid "ValueError: No cohorts available" by selecting only a few different years at random.
127+
selected_years = random.sample(range(1900, 2100), 3)
128+
random_years_as_list = np.random.choice(selected_years, len(sample_metadata_df))
129129
random_years_as_period_index = pd.PeriodIndex(random_years_as_list, freq="Y")
130130
extra_metadata_df = pd.DataFrame(
131131
{

0 commit comments

Comments
 (0)