{"record":{"id":"36e70145fe9f257b","repo":"dotnet/machinelearning","slug":"mismatchedcolumnlengths-36e701","errorCode":null,"errorMessage":"MismatchedColumnLengths","messagePattern":"MismatchedColumnLengths","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/StringDataFrameColumn.BinaryOperations.cs","lineNumber":20,"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\nusing System;\nusing System.Collections.Generic;\nusing System.Globalization;\nusing System.Linq;\nusing System.Text;\n\nnamespace Microsoft.Data.Analysis\n{\n    public partial class StringDataFrameColumn : DataFrameColumn\n    {\n        /// <inheritdoc/>\n        public override DataFrameColumn Add(DataFrameColumn column, bool inPlace = false)\n        {\n            if (Length != column.Length)\n            {\n                throw new ArgumentException(Strings.MismatchedColumnLengths, nameof(column));\n            }\n            StringDataFrameColumn ret = inPlace ? this : Clone();\n            for (long i = 0; i < Length; i++)\n            {\n                ret[i] += column[i].ToString();\n            }\n            return ret;\n        }\n\n        public static StringDataFrameColumn operator +(StringDataFrameColumn column, string value)\n        {\n            return column.Add(value);\n        }\n\n        public static StringDataFrameColumn operator +(string value, StringDataFrameColumn column)\n        {\n            return Add(value, column);\n        }","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/StringDataFrameColumn.BinaryOperations.cs#L2-L38","documentation":"StringDataFrameColumn.Add (and its arithmetic family) requires both columns to have the same Length; element i is combined with element i. When Length != column.Length it throws ArgumentException with the message Strings.MismatchedColumnLengths ('MismatchedColumnLengths'). The library has no broadcasting or alignment for binary column operations.","triggerScenarios":"Calling stringColumn.Add(otherColumn) — including the + operator and Add(column, inPlace:true) — where the two columns have different row counts, e.g. Length=100 vs Length=90 after a filter/join on only one side.","commonSituations":"Filtering one column independently before concatenating; misaligned results from a left join; appending rows to one column only; mixing columns from DataFrames of different sizes.","solutions":["Ensure both columns have the same Length before adding: filter/pad/truncate so counts match","Verify the intended operand — if you meant to append a constant, use the string overload (Add(string value)) instead of a column overload","Re-derive both columns from the same filtered DataFrame so row counts stay in sync","Check for null/missing rows removed on one side only; rebuild with an index-based join"],"exampleFix":"// before\nvar filtered = df[\"A\"].ElementwiseLessThan(10); // shorter after use elsewhere\nvar result = strColumn.Add(otherStrColumn); // Lengths 100 vs 90 -> ArgumentException\n// after\nif (strColumn.Length != otherStrColumn.Length)\n    throw new InvalidOperationException(\"Align columns before Add\");\nvar result = strColumn.Add(otherStrColumn);","handlingStrategy":"validation","validationCode":"if (left.Length != right.Length)\n    throw new InvalidOperationException($\"Cannot Add: lengths differ ({left.Length} vs {right.Length})\");","typeGuard":"bool SameLength(DataFrameColumn a, DataFrameColumn b) => a.Length == b.Length;","tryCatchPattern":"try { var result = strColumn.Add(otherColumn); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"MismatchedColumnLengths\")) {\n    // align lengths: filter both columns from the same source or pad/truncate\n}","preventionTips":["Always derive related columns from the same filtered DataFrame so lengths stay in sync","Check column.Length equality before every element-wise binary operation","Remember there is no broadcasting for column-vs-column ops; scalars are the broadcast path","Validate row counts after joins/filters before combining columns"],"tags":["dotnet","argument","dataframe","column-length"],"backgroundTag":"schema-validation-failed","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"}