apache/beam · error · ValueError
"RobustZScore.score_one expected univariate input, but got
Error message
"RobustZScore.score_one expected univariate input, but got %s", str(x)
What it means
RobustZScore.score_one computes the robust z-score of a single point and requires a univariate beam.Row with exactly one field. Rows with a different field count raise ValueError. The score math (x - median) / MAD only applies to one value per point.
Solutions
- Project the input to a single numeric field before scoring.
- Ensure the score-stage Row shape matches the learn-stage Row shape.
- Add a pre-scoring validation step that rejects or logs multi-field rows.
Example fix
// before enriched_rows | beam.Map(detector.score_one) // after enriched_rows | 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"RobustZScore.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
- Score only the projected single-field Row
- Avoid enrichment between learn and score without re-projecting
- Validate schema after windowing/joins
When it happens
Trigger: Scoring beam.Row objects with multiple attributes or empty rows through RobustZScore.score_one, often when the scored PCollection still contains metadata columns.
Common situations: Joining/enriching rows before scoring so they gain extra fields; passing raw source rows; inconsistent shaping between the learn and score stages of the pipeline.
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
- ZScore.learn_one expected univariate input, but got
- ZScore.score_one expected univariate input, but got
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/3fb8b443eeb38d82.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/ml/anomaly/detectors/robust_zscore.py:98
if len(x.__dict__) != 1:
raise ValueError(
"RobustZScore.learn_one expected univariate input, but got %s",
str(x))
v = next(iter(x))
self._mad_tracker.push(v)
def score_one(self, x: beam.Row) -> Optional[float]:
"""Scores a data point using the Robust Z-Score.
Args:
x: A `beam.Row` containing a single numerical value.
Returns:
float | None: The Robust Z-Score.
"""
if len(x.__dict__) != 1:
raise ValueError(
"RobustZScore.score_one expected univariate input, but got %s",
str(x))
v = next(iter(x))
if v is None or math.isnan(v):
return None
median = self._mad_tracker.get_median()
mad = self._mad_tracker.get()
# not enough data points to compute median or median absolute deviation
if math.isnan(mad) or math.isnan(median):
return float('NaN')
if abs(mad) < EPSILON:
return 0.0
return abs(RobustZScore.SCALE_FACTOR * (v - median) / mad)View on GitHub (pinned to 12126d8942)