{"record":{"id":"944184643c94cba3","repo":"apache/beam","slug":"type-must-be-a-non-complex-number-v","errorCode":null,"errorMessage":"type must be a non-complex number: %v","messagePattern":"type must be a non-complex number: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/testing/passert/floats.go","lineNumber":160,"sourceCode":"\terrorStrings := []string{}\n\tif len(tooLow) != 0 {\n\t\tsort.Float64s(tooLow)\n\t\terrorStrings = append(errorStrings, fmt.Sprintf(\"values below minimum value %v: %v\", f.Lo, tooLow))\n\t}\n\tif len(tooHigh) != 0 {\n\t\tsort.Float64s(tooHigh)\n\t\terrorStrings = append(errorStrings, fmt.Sprintf(\"values above maximum value %v: %v\", f.Hi, tooHigh))\n\t}\n\treturn errors.New(strings.Join(errorStrings, \"\\n\"))\n}\n\nfunc toFloat(input beam.T) float64 {\n\treturn reflect.ValueOf(input.(any)).Convert(reflectx.Float64).Interface().(float64)\n}\n\nfunc validateNonComplexNumber(t reflect.Type) error {\n\tif !reflectx.IsNumber(t) || reflectx.IsComplex(t) {\n\t\treturn errors.Errorf(\"type must be a non-complex number: %v\", t)\n\t}\n\treturn nil\n}\n","sourceCodeStart":142,"sourceCodeEnd":164,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/testing/passert/floats.go#L142-L164","documentation":"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'.","triggerScenarios":"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.","commonSituations":"Asserting on complex-valued PCollections from signal processing; accidentally passing a string-typed or generic beam.T PCollection to a float assertion.","solutions":["Use a real numeric element type or convert the PCollection to float64 before asserting.","For complex data, assert on real/imag parts or magnitudes separately.","Confirm the PCollection element type with beam's type helpers.","Remove custom coders that mislabel element types."],"exampleFix":"// before\npassert.EqualsFloat(s, complexCol) // complex128 elements\n// after\nreals := beam.ParDo(s, func(c complex128) float64 { return real(c) }, complexCol)\npassert.EqualsFloat(s, reals)","handlingStrategy":"type-guard","validationCode":"typ := beam.GetReturnType(beam.Encoded(w.Pipeline(), col))\nif !reflectx.IsNumber(typ) || reflectx.IsComplex(typ) {\n\tt.Fatalf(\"assertion requires real numeric elements, got %v\", typ)\n}","typeGuard":"func isRealNumber(v any) bool {\n\tt := reflect.TypeOf(v)\n\treturn t != nil && reflectx.IsNumber(t) && !reflectx.IsComplex(t)\n}","tryCatchPattern":null,"preventionTips":["Only call Floats assertions on float/int element PCollections.","Convert complex data to real parts before asserting.","Verify PCollection element types with beam type helpers."],"tags":["go","beam","testing","passert","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}