{"record":{"id":"b9dba9d8afdf36de","repo":"dotnet/machinelearning","slug":"expected-column-to-hold-values-of-type-0","errorCode":null,"errorMessage":"Expected column to hold values of type {0}","messagePattern":"Expected column to hold values of type (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs","lineNumber":987,"sourceCode":"                    throw new NotSupportedException();\n                case Type decimalType when decimalType == typeof(decimal):\n                    if (typeof(U) == typeof(bool))\n                    {\n                        throw new NotSupportedException();\n                    }\n                    if (typeof(U) == typeof(T))\n                    {\n                        // No conversions\n                        PrimitiveDataFrameColumn<U> primitiveColumn = this as PrimitiveDataFrameColumn<U>;\n                        PrimitiveDataFrameColumn<U> newColumn = inPlace ? primitiveColumn : primitiveColumn.Clone();\n                        newColumn._columnContainer.HandleOperation(operation, column._columnContainer);\n                        return newColumn;\n                    }\n                    else\n                    {\n                        if (inPlace)\n                        {\n                            throw new ArgumentException(string.Format(Strings.MismatchedColumnValueType, typeof(T)), nameof(column));\n                        }\n                        PrimitiveDataFrameColumn<decimal> decimalColumn = CloneAsDecimalColumn();\n                        decimalColumn._columnContainer.HandleOperation(operation, column.CloneAsDecimalColumn()._columnContainer);\n                        return decimalColumn;\n                    }\n                case Type DateTimeType when DateTimeType == typeof(DateTime):\n                    throw new NotSupportedException();\n                case Type byteType when byteType == typeof(byte):\n                case Type charType when charType == typeof(char):\n                case Type doubleType when doubleType == typeof(double):\n                case Type floatType when floatType == typeof(float):\n                case Type intType when intType == typeof(int):\n                case Type longType when longType == typeof(long):\n                case Type sbyteType when sbyteType == typeof(sbyte):\n                case Type shortType when shortType == typeof(short):\n                case Type uintType when uintType == typeof(uint):\n                case Type ulongType when ulongType == typeof(ulong):\n                case Type ushortType when ushortType == typeof(ushort):","sourceCodeStart":969,"sourceCodeEnd":1005,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs#L969-L1005","documentation":"For a decimal column T=decimal, binary operations with a column of a different non-bool type U are only supported out-of-place: the library clones itself as decimal and operates on a decimal-converted right column. If inPlace is true and typeof(U) != typeof(T), it throws ArgumentException (Strings.MismatchedColumnValueType, 'Expected column to hold values of type {0}') because the result type would differ from the in-place target.","triggerScenarios":"Calling an in-place binary operation API (e.g. Add(column, inPlace: true), or the InPlace variant) on a PrimitiveDataFrameColumn<decimal> with a right column whose element type is not decimal (e.g. int, double).","commonSituations":"Using the in-place overload for convenience while mixing int and decimal columns; migrating code that previously used the non-in-place overload to in-place form.","solutions":["Use the non-in-place operation (inPlace: false) so the result is a new decimal column","Convert the right-hand column to decimal first (CloneAsDecimalColumn or Cast) so typeof(U) == typeof(T)","Change the right column's construction to produce PrimitiveDataFrameColumn<decimal>"],"exampleFix":"// before\nvar result = decimalColumn.Add(intColumn, inPlace: true); // ArgumentException\n// after\nvar result = decimalColumn.Add(intColumn, inPlace: false); // returns decimal column\n// or\nvar result = decimalColumn.Add(intColumn.CloneAsDecimalColumn(), inPlace: true);","handlingStrategy":"type-guard","validationCode":"if (inPlace && decimalColumn.DataType != other.DataType)\n    throw new InvalidOperationException(\"In-place decimal ops require the other column to be decimal; use inPlace: false otherwise\");","typeGuard":"bool SafeInPlace(DataFrameColumn left, DataFrameColumn right, bool inPlace) =>\n    !inPlace || left.DataType == right.DataType;","tryCatchPattern":"try\n{\n    result = decimalColumn.Add(other, inPlace: true);\n}\ncatch (ArgumentException ex) when (ex.ParamName == \"column\")\n{\n    result = decimalColumn.Add(other, inPlace: false);\n}","preventionTips":["Only use inPlace:true with same-typed columns","Default to non-in-place when mixing column types","Check DataType equality before in-place calls"],"tags":["dataframe","argument","decimal","type-mismatch","dotnet"],"backgroundTag":"type-mismatch","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"}