Skip to content

Commit 55f4f3b

Browse files
committed
fix: resolve NumPy 2.x boolean ambiguity in SNP frequency analysis
Replace built-in all() with .all() method on pandas Series in _prep_samples_for_cohort_grouping() to avoid NumPy 2.x ValueError. NumPy 2.x raises ValueError when attempting to evaluate the truth value of an array/Series with more than one element in a boolean context. Before: if not all(df_samples[period_by].apply(...)): After: if not df_samples[period_by].apply(...).all(): The .all() method correctly reduces the Series to a single boolean value, maintaining identical behavior with both NumPy 1.26.x and 2.x. Fixes allele_frequencies_advanced test failures under NumPy 2.x.
1 parent 8aa3891 commit 55f4f3b

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

malariagen_data/anoph/frq_base.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ def _prep_samples_for_cohort_grouping(*, df_samples, area_by, period_by, taxon_b
5353
)
5454

5555
# Raise a ValueError if the specified period_by column does not contain instances pd.Period.
56-
if not all(
57-
df_samples[period_by].apply(
58-
lambda value: pd.isnull(value) or isinstance(value, pd.Period)
59-
)
60-
):
56+
if not df_samples[period_by].apply(
57+
lambda value: pd.isnull(value) or isinstance(value, pd.Period)
58+
).all():
6159
raise TypeError(
6260
f"Invalid values in {period_by!r} column. Must be either pandas.Period or null."
6361
)

0 commit comments

Comments
 (0)