{"record":{"id":"aabbb791ecddde42","repo":"dotnet/machinelearning","slug":"0-1","errorCode":null,"errorMessage":"{0} {1}","messagePattern":"\\{0\\} \\{1\\}","errorType":"exception","errorClass":"System.ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrame.cs","lineNumber":403,"sourceCode":"            GroupBy<TKey> group = GroupBy(columnName) as GroupBy<TKey>;\n\n            if (group == null)\n            {\n                DataFrameColumn column = this[columnName];\n                throw new InvalidCastException(String.Format(Strings.BadColumnCastDuringGrouping, columnName, column.DataType, typeof(TKey)));\n            }\n\n            return group;\n        }\n\n        // In GroupBy and ReadCsv calls, columns get resized. We need to set the RowCount to reflect the true Length of the DataFrame. This does internal validation\n        internal void SetTableRowCount(long rowCount)\n        {\n            // Even if current RowCount == rowCount, do the validation\n            for (int i = 0; i < Columns.Count; i++)\n            {\n                if (Columns[i].Length != rowCount)\n                    throw new ArgumentException(String.Format(\"{0} {1}\", Strings.MismatchedRowCount, Columns[i].Name));\n            }\n            _columnCollection.RowCount = rowCount;\n        }\n\n        /// <summary>\n        /// Returns a DataFrame with no missing values\n        /// </summary>\n        /// <param name=\"options\"></param>\n        public DataFrame DropNulls(DropNullOptions options = DropNullOptions.Any)\n        {\n            var filter = new BooleanDataFrameColumn(\"Filter\");\n\n            if (options == DropNullOptions.Any)\n            {\n                filter.AppendMany(true, Rows.Count);\n                var buffers = filter.ColumnContainer.Buffers;\n\n                foreach (var column in Columns)","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrame.cs#L385-L421","documentation":"SetTableRowCount validates that every column's Length equals the requested rowCount; if any column disagrees it throws ArgumentException formatted as \"{MismatchedRowCount} {columnName}\", i.e. '{0} {1}'. This is an internal consistency check run when DataFrame state changes (Count, First, Head, Tail, Max, Min call into it). It indicates columns of unequal length were added to the DataFrame.","triggerScenarios":"Adding columns of different lengths to a DataFrame (e.g. via column construction or Append paths) and then triggering operations that read/set the row count; mutating a column's Length independently of the others.","commonSituations":"Building a DataFrame column-by-column from sources of different sizes (shorter CSV column, filtered array); a bug in user code that resized one column after assembly; deserializing columns from mismatched arrays.","solutions":["Make all columns the same length before forming the DataFrame — pad shorter sources or truncate longer ones.","Check each column's Length against the first column's Length before adding it to the DataFrame.","Catch ArgumentException and inspect the column named in the message; fix that column's length.","Ensure column mutations (Resize/Append on columns) are applied to every column equally."],"exampleFix":"// before\ndf.Columns.Add(stringColumnWithDifferentLength);\n// after\nif (newCol.Length != df.Rows.Count)\n    newCol.Resize(df.Rows.Count); // or pad/truncate to match\ndf.Columns.Add(newCol);","handlingStrategy":"validation","validationCode":"long expected = df.Columns[0].Length;\nfor (int i = 1; i < df.Columns.Count; i++)\n    if (df.Columns[i].Length != expected)\n        throw new InvalidOperationException($\"Column '{df.Columns[i].Name}' length {df.Columns[i].Length} != {expected}\");","typeGuard":"bool IsRectangular(DataFrame df) => df.Columns.All(c => c.Length == df.Columns[0].Length);","tryCatchPattern":"try { df.SetTableRowCount(n); }\ncatch (ArgumentException ex) { logger.LogError(ex, \"Column lengths inconsistent: {0}\", ex.Message); throw; }","preventionTips":["Pad or truncate every column to the same length before assembling a DataFrame","Never Resize/append to one column independently of the others","Assert column equality of lengths in unit tests on DataFrame builders"],"tags":["inconsistent-state","column-length","row-count","invariant"],"backgroundTag":"internal-invariant-violation","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"}