apache/beam · error
TryEqualsFloat failed
Error message
TryEqualsFloat failed: %v
What it means
passert.EqualsFloat is the panicking wrapper around TryEqualsFloat, which loads two float PCollections into memory, sorts them, and compares element-by-element within a threshold. If TryEqualsFloat returns any error (pipeline construction/validation issue), EqualsFloat panics so the test fails immediately.
Solutions
- Call passert.TryEqualsFloat directly and handle/log the returned error instead of panicking.
- Ensure both PCollections have non-complex numeric element types before asserting.
- Print the underlying error via a small wrapper to diagnose the root cause.
Example fix
// before
passert.EqualsFloat(s, observed, expected, 1e-6) // panics on error
// after
if err := passert.TryEqualsFloat(s, observed, expected, 1e-6); err != nil {
t.Fatalf("float assertion failed: %v", err)
} Defensive patterns
Strategy: validation
Validate before calling
// check element types are non-complex numeric before asserting
func isNonComplexNumeric(t typex.FullType) bool {
switch t.Type().Kind() {
case reflect.Float32, reflect.Float64, reflect.Int, reflect.Int32, reflect.Int64:
return true
}
return false
} Try / catch
func safeEqualsFloat(t *testing.T, s beam.Scope, obs, exp beam.PCollection, th float64) {
defer func() { if r := recover(); r != nil { t.Fatalf("EqualsFloat panicked: %v", r) } }()
passert.EqualsFloat(s, obs, exp, th)
} Prevention
- Prefer TryEqualsFloat in test helpers to get errors instead of panics
- Assert only on float32/float64 (and int) element PCollections
- Verify upstream transform output types before passert calls
When it happens
Trigger: Calling passert.EqualsFloat(s, observed, expected, threshold) where TryEqualsFloat fails — most commonly when observed or expected is not a non-complex numeric PCollection (e.g. complex numbers or non-numeric element types).
Common situations: Pipeline tests asserting equality on float collections whose element type is complex128, or passing PCollections produced by a transform that changed the element type.
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
- missing entries (missing in actual, present in expected)
- observed PCollection has incompatible type
- passert.Count( ) = , want
- passert.Diff input PColections don't have matching types
- passert.Hash( ) = ( , ), want ( , )
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/daf94044baee1360.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/testing/passert/floats.go:42
"github.com/apache/beam/sdks/v2/go/pkg/beam"
"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/reflectx"
"github.com/apache/beam/sdks/v2/go/pkg/beam/internal/errors"
"github.com/apache/beam/sdks/v2/go/pkg/beam/register"
)
func init() {
register.DoFn2x1[[]byte, func(*beam.T) bool, error]((*boundsFn)(nil))
register.DoFn3x1[[]byte, func(*beam.T) bool, func(*beam.T) bool, error]((*thresholdFn)(nil))
register.Emitter1[beam.T]()
register.Iter1[beam.T]()
}
// EqualsFloat calls into TryEqualsFloat, checkong that two PCollections of non-complex
// numeric types are equal, with each element being within a provided threshold of an
// expected value. Panics if TryEqualsFloat returns an error.
func EqualsFloat(s beam.Scope, observed, expected beam.PCollection, threshold float64) {
if err := TryEqualsFloat(s, observed, expected, threshold); err != nil {
panic(fmt.Sprintf("TryEqualsFloat failed: %v", err))
}
}
// TryEqualsFloat checks that two PCollections of floats are equal, with each element
// being within a specified threshold of its corresponding element. Both PCollections
// are loaded into memory, sorted, and compared element by element. Returns an error if
// the PCollection types are complex or non-numeric.
func TryEqualsFloat(s beam.Scope, observed, expected beam.PCollection, threshold float64) error {
errorStrings := []string{}
observedT := beam.ValidateNonCompositeType(observed)
if obsErr := validateNonComplexNumber(observedT.Type()); obsErr != nil {
errorStrings = append(errorStrings, fmt.Sprintf("observed PCollection has incompatible type: %v", obsErr))
}
expectedT := beam.ValidateNonCompositeType(expected)
validateNonComplexNumber(expectedT.Type())
if expErr := validateNonComplexNumber(expectedT.Type()); expErr != nil {
errorStrings = append(errorStrings, fmt.Sprintf("expected PCollection has incompatible type: %v", expErr))
}View on GitHub (pinned to 12126d8942)