apache/beam · error

type must be a non-complex number

Error message

type must be a non-complex number: %v

What it means

passert.Floats helpers require real numeric types because values are converted to float64 via toFloat. validateNonComplexNumber, called by TryEqualsFloat and AllWithinBounds, rejects complex numbers and non-numeric types with 'type must be a non-complex number: %v'.

Solutions

  1. Use a real numeric element type or convert the PCollection to float64 before asserting.
  2. For complex data, assert on real/imag parts or magnitudes separately.
  3. Confirm the PCollection element type with beam's type helpers.
  4. Remove custom coders that mislabel element types.

Example fix

// before
passert.EqualsFloat(s, complexCol) // complex128 elements
// after
reals := beam.ParDo(s, func(c complex128) float64 { return real(c) }, complexCol)
passert.EqualsFloat(s, reals)
Defensive patterns

Strategy: type-guard

Validate before calling

typ := beam.GetReturnType(beam.Encoded(w.Pipeline(), col))
if !reflectx.IsNumber(typ) || reflectx.IsComplex(typ) {
	t.Fatalf("assertion requires real numeric elements, got %v", typ)
}

Type guard

func isRealNumber(v any) bool {
	t := reflect.TypeOf(v)
	return t != nil && reflectx.IsNumber(t) && !reflectx.IsComplex(t)
}

Prevention

When it happens

Trigger: Calling passert.TryEqualsFloat or AllWithinBounds (or their Equals variants) on a PCollection whose element type is complex64/complex128, a string, or otherwise not a real number.

Common situations: Asserting on complex-valued PCollections from signal processing; accidentally passing a string-typed or generic beam.T PCollection to a float assertion.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/944184643c94cba3. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/testing/passert/floats.go:160

	errorStrings := []string{}
	if len(tooLow) != 0 {
		sort.Float64s(tooLow)
		errorStrings = append(errorStrings, fmt.Sprintf("values below minimum value %v: %v", f.Lo, tooLow))
	}
	if len(tooHigh) != 0 {
		sort.Float64s(tooHigh)
		errorStrings = append(errorStrings, fmt.Sprintf("values above maximum value %v: %v", f.Hi, tooHigh))
	}
	return errors.New(strings.Join(errorStrings, "\n"))
}

func toFloat(input beam.T) float64 {
	return reflect.ValueOf(input.(any)).Convert(reflectx.Float64).Interface().(float64)
}

func validateNonComplexNumber(t reflect.Type) error {
	if !reflectx.IsNumber(t) || reflectx.IsComplex(t) {
		return errors.Errorf("type must be a non-complex number: %v", t)
	}
	return nil
}

View on GitHub (pinned to 12126d8942)