"""geometric_mean — Geometric mean of positive values.""" import math import numpy as np def geometric_mean(values: list[float]) -> float: """Return the geometric mean of the positive elements in values. Filters out non-positive numbers before computing exp(mean(log(x))). Returns math.nan if there are no positive values. Args: values: List of numeric values (non-positive elements are ignored). Returns: Geometric mean as float, or math.nan if no positive values exist. """ positives = [v for v in values if v > 0] if not positives: return math.nan arr = np.array(positives, dtype=float) return float(np.exp(np.mean(np.log(arr))))