{"record":{"id":"f7a28a965485751d","repo":"dotnet/machinelearning","slug":"strings-mismatchedcolumnlengths-f7a28a","errorCode":null,"errorMessage":"Strings.MismatchedColumnLengths","messagePattern":"Strings\\.MismatchedColumnLengths","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperationImplementations.Exploded.cs","lineNumber":22,"sourceCode":"// The .NET Foundation licenses this file to you under the MIT license.\n// See the LICENSE file in the project root for more information.\n\n// Generated from DataFrameColumn.BinaryOperationImplementations.ExplodedColumns.tt. Do not modify directly\n\nusing System;\nusing System.Collections.Generic;\n\nnamespace Microsoft.Data.Analysis\n{\n\n    public partial class DecimalDataFrameColumn\n    {\n        //Binary Operations\n        internal DecimalDataFrameColumn HandleOperationImplementation(BinaryOperation operation, DecimalDataFrameColumn column, bool inPlace = false)\n        {\n            if (column.Length != Length)\n            {\n                throw new ArgumentException(Strings.MismatchedColumnLengths, nameof(column));\n            }\n            var newColumn = inPlace ? this : (DecimalDataFrameColumn)Clone();\n            newColumn.ColumnContainer.HandleOperation(operation, column.ColumnContainer);\n            return newColumn;\n        }\n\n        //Binary Scalar Operations\n        internal DecimalDataFrameColumn HandleOperationImplementation(BinaryOperation operation, decimal right, bool inPlace = false)\n        {\n            var newColumn = inPlace ? this : (DecimalDataFrameColumn)Clone();\n            newColumn.ColumnContainer.HandleOperation(operation, right);\n            return newColumn;\n        }\n\n        internal DecimalDataFrameColumn HandleReverseOperationImplementation(BinaryOperation operation, decimal right, bool inPlace = false)\n        {\n            var newColumn = inPlace ? this : (DecimalDataFrameColumn)Clone();\n            newColumn.ColumnContainer.HandleReverseOperation(operation, right);","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.BinaryOperationImplementations.Exploded.cs#L4-L40","documentation":"Binary arithmetic between two DecimalDataFrameColumn operands requires both columns to have the same number of rows, since the operation is applied element-wise. When the operand column's Length differs from this column's Length, HandleOperationImplementation throws ArgumentException with paramName `column` and message Strings.MismatchedColumnLengths.","triggerScenarios":"Calling Add/Subtract/Multiply/Divide/Modulo (or the +,-,*,/,% operators) on two DecimalDataFrameColumn instances of different Length, optionally with inPlace: true.","commonSituations":"Arithmetic between columns from different DataFrames with different row counts, after filtering one DataFrame but not the other, or mixing a full column with a sliced column.","solutions":["Before the operation, verify column.Length == thisColumn.Length; if not, align the data (filter, slice, or join) so both have the same rows.","Ensure both columns come from the same DataFrame or were derived with the same row selection.","For scalar/element-wise math on mismatched columns, first truncate the longer column to the shorter length via slicing/cloning."],"exampleFix":"// before\nvar result = price * qty; // price.Length == 100, qty.Length == 90\n// after\nif (price.Length != qty.Length)\n    throw new InvalidOperationException(\"Align columns before arithmetic\");\nvar result = price * qty;","handlingStrategy":"validation","validationCode":"if (left.Length != right.Length) throw new InvalidOperationException($\"Column length mismatch: {left.Length} vs {right.Length}\");","typeGuard":"static bool SameLength(DecimalDataFrameColumn a, DecimalDataFrameColumn b) => a.Length == b.Length;","tryCatchPattern":"try { var result = left * right; }\ncatch (ArgumentException ex) when (ex.Message == Strings.MismatchedColumnLengths || ex.ParamName == \"column\")\n{\n    // align/slice columns and retry\n}","preventionTips":["Derive operand columns from the same DataFrame","Check Length equality in a helper before any column arithmetic","After filtering, re-derive all dependent columns together"],"tags":["argumentexception","binary-operation","decimal-column","length-mismatch"],"backgroundTag":"shape-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"}