apache/beam · error · ValueError
ZScore.score_one expected univariate input, but got
Error message
ZScore.score_one expected univariate input, but got %s
What it means
ZScore.score_one computes the z-score of a single point and requires a univariate beam.Row with exactly one field; otherwise a ValueError is raised. Scoring shares the univariate constraint enforced at learning time.
Solutions
- Map to a single-field Row before score_one.
- Keep the learn/score input shapes identical by reusing the same projection transform.
- If multiple features must be scored together, instantiate one ZScore per feature.
Example fix
// before windowed | beam.Map(detector.score_one) // after windowed | beam.Map(lambda r: beam.Row(value=r.metric)) | beam.Map(detector.score_one)
Defensive patterns
Strategy: validation
Validate before calling
if len(row.__dict__) != 1:
raise ValueError(f"ZScore.score_one requires exactly one field, got: {list(row.__dict__)}") Type guard
def is_univariate(row): return len(getattr(row, '__dict__', {})) == 1 Try / catch
try:
score = detector.score_one(row)
except ValueError as e:
score = None
logger.warning("unscorable row %r: %s", row, e) Prevention
- Re-project rows after any enrichment before scoring
- Assert row arity in tests
- Keep the learn/score shapes symmetric
When it happens
Trigger: Scoring rows with multiple attributes (or zero) through ZScore.score_one, typically when the scored stream retains extra columns like keys or timestamps.
Common situations: Piping the original multi-column PCollection into both learn and score; enrichment steps adding fields between learn and score; accidental reuse of a generic row-mapping transform.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- "IQR.learn_one expected univariate input, but got
- "IQR.score_one expected univariate input, but got
- "RobustZScore.learn_one expected univariate input, but got
- "RobustZScore.score_one expected univariate input, but got
- ZScore.learn_one expected univariate input, but got
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/1b5de3ed59d35b79.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/ml/anomaly/detectors/zscore.py:109
if len(x.__dict__) != 1:
raise ValueError(
"ZScore.learn_one expected univariate input, but got %s", str(x))
v = next(iter(x))
self._stdev_tracker.push(v)
self._sub_stat_tracker.push(v)
def score_one(self, x: beam.Row) -> Optional[float]:
"""Scores a data point using the Z-Score.
Args:
x: A `beam.Row` containing a single numerical value.
Returns:
float | None: The Z-Score.
"""
if len(x.__dict__) != 1:
raise ValueError(
"ZScore.score_one expected univariate input, but got %s", str(x))
v = next(iter(x))
if v is None or math.isnan(v):
return None
sub_stat = self._sub_stat_tracker.get()
stdev = self._stdev_tracker.get()
# not enough data points to compute sub_stat or standard deviation
if math.isnan(stdev) or math.isnan(sub_stat):
return float('NaN')
if abs(stdev) < EPSILON:
return 0.0
return abs((v - sub_stat) / stdev)
View on GitHub (pinned to 12126d8942)