{"record":{"id":"5638b127452b697b","repo":"dotnet/machinelearning","slug":"bad-data-kind-in-columntypeextensions-numbertypefr","errorCode":null,"errorMessage":"Bad data kind in ColumnTypeExtensions.NumberTypeFromKind: {kind}","messagePattern":"Bad data kind in ColumnTypeExtensions\\.NumberTypeFromKind: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.Core/Data/ColumnTypeExtensions.cs","lineNumber":166,"sourceCode":"                return NumberDataViewType.Int16;\n            case InternalDataKind.U2:\n                return NumberDataViewType.UInt16;\n            case InternalDataKind.I4:\n                return NumberDataViewType.Int32;\n            case InternalDataKind.U4:\n                return NumberDataViewType.UInt32;\n            case InternalDataKind.I8:\n                return NumberDataViewType.Int64;\n            case InternalDataKind.U8:\n                return NumberDataViewType.UInt64;\n            case InternalDataKind.R4:\n                return NumberDataViewType.Single;\n            case InternalDataKind.R8:\n                return NumberDataViewType.Double;\n        }\n\n        Contracts.Assert(false);\n        throw new InvalidOperationException($\"Bad data kind in {nameof(ColumnTypeExtensions)}.{nameof(NumberTypeFromKind)}: {kind}\");\n    }\n}\n","sourceCodeStart":148,"sourceCodeEnd":169,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.Core/Data/ColumnTypeExtensions.cs#L148-L169","documentation":"NumberTypeFromKind is the internal switch mapping InternalDataKind values (numeric kinds like I1..R8) to NumberDataViewType instances. If the kind is not a numeric kind (or is an undefined kind value), it asserts the invariant and throws InvalidOperationException 'Bad data kind in ColumnTypeExtensions.NumberTypeFromKind: {kind}'. It signals a non-numeric or corrupt kind reached a numeric-only code path.","triggerScenarios":"Calling NumberTypeFromType with a type that TryGetDataKind maps to a non-numeric InternalDataKind (e.g. TX (text), BL (bool), DT (DateTime), TS (TimeSpan)), or passing a raw out-of-range InternalDataKind value into the kind path of PrimitiveTypeFromKind.","commonSituations":"Attempting to build a number column type from a string/bool/datetime kind; stale serialized kind values from a different Microsoft.Data.DataView version; constructing DataView types programmatically from user-supplied kind strings.","solutions":["Ensure the DataKind is numeric (I1/I2/I4/I8/U1/U2/U4/U8/R4/R8) before requesting a NumberDataViewType.","For non-numeric kinds use the appropriate DataView type (TextDataViewType.Instance, BooleanDataViewType.Instance, DateTimeDataViewType.Instance) instead.","Validate kind strings via InternalDataKind.TryParse and whitelist numeric kinds before conversion.","Align Microsoft.Data.DataView and Microsoft.ML package versions so kind values are interpreted consistently."],"exampleFix":"// before\nvar type = ColumnTypeExtensions.NumberTypeFromType(typeof(string));\n// after\nvar type = typeof(string) == t\n    ? TextDataViewType.Instance\n    : ColumnTypeExtensions.NumberTypeFromType(t);","handlingStrategy":"type-guard","validationCode":"var numericKinds = new HashSet<InternalDataKind> { InternalDataKind.I1, InternalDataKind.I2,\n    InternalDataKind.I4, InternalDataKind.I8, InternalDataKind.U1, InternalDataKind.U2,\n    InternalDataKind.U4, InternalDataKind.U8, InternalDataKind.R4, InternalDataKind.R8 };\nif (!numericKinds.Contains(kind))\n    throw new ArgumentException($\"{kind} is not a numeric DataKind\");","typeGuard":"static bool IsNumericKind(InternalDataKind kind) =>\n    kind is InternalDataKind.I1 or InternalDataKind.I2 or InternalDataKind.I4\n        or InternalDataKind.I8 or InternalDataKind.U1 or InternalDataKind.U2\n        or InternalDataKind.U4 or InternalDataKind.U8 or InternalDataKind.R4\n        or InternalDataKind.R8;","tryCatchPattern":"try\n{\n    numberType = ColumnTypeExtensions.NumberTypeFromType(t);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"NumberTypeFromKind\"))\n{\n    // kind is non-numeric; map manually\n    numberType = null;\n}","preventionTips":["Check kind is numeric before requesting a NumberDataViewType.","Use TextDataViewType/BooleanDataViewType/DateTimeDataViewType for non-numeric kinds.","Keep Microsoft.Data.DataView and Microsoft.ML versions aligned to avoid kind-value drift.","Never construct InternalDataKind from unchecked user input."],"tags":["mlnet","dataview","datakind","invalid-operation"],"backgroundTag":"unsupported-dtype","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}