{"record":{"id":"b09a960ff51fc774","repo":"dotnet/machinelearning","slug":"column-lengths-are-mismatched","errorCode":null,"errorMessage":"Column lengths are mismatched","messagePattern":"Column lengths are mismatched","errorType":"validation","errorClass":"System.ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrame.cs","lineNumber":484,"sourceCode":"        {\n            DataFrame ret = inPlace ? this : Clone();\n            for (int i = 0; i < ret.Columns.Count; i++)\n            {\n                ret.Columns[i].FillNulls(value, inPlace: true);\n            }\n            return ret;\n        }\n\n        /// <summary>\n        /// Fills <see langword=\"null\" /> values in each column with values from <paramref name=\"values\"/>.\n        /// </summary>\n        /// <param name=\"values\">The values to replace <see langword=\"null\" /> with, one value per column. Should be equal to the number of columns in this <see cref=\"DataFrame\"/>. </param>\n        /// <param name=\"inPlace\">A boolean flag to indicate if the operation should be in place</param>\n        /// <returns>A new <see cref=\"DataFrame\"/> if <paramref name=\"inPlace\"/> is not set. Returns this <see cref=\"DataFrame\"/> otherwise.</returns>\n        public DataFrame FillNulls(IList<object> values, bool inPlace = false)\n        {\n            if (values.Count != Columns.Count)\n                throw new ArgumentException(Strings.MismatchedColumnLengths, nameof(values));\n\n            DataFrame ret = inPlace ? this : Clone();\n            for (int i = 0; i < ret.Columns.Count; i++)\n            {\n                Columns[i].FillNulls(values[i], inPlace: true);\n            }\n            return ret;\n        }\n\n        private void ResizeByOneAndAppend(DataFrameColumn column, object value)\n        {\n            long length = column.Length;\n            column.Resize(length + 1);\n            column[length] = value;\n        }\n\n        /// <summary> \n        /// Appends rows to the DataFrame ","sourceCodeStart":466,"sourceCodeEnd":502,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrame.cs#L466-L502","documentation":"FillNulls(IList<object> values) requires one replacement value per column; when values.Count != Columns.Count it throws ArgumentException with Strings.MismatchedColumnLengths ('Column lengths are mismatched') naming the `values` parameter. The library maps values[i] positionally onto columns[i], so a count mismatch would silently mis-assign values.","triggerScenarios":"df.FillNulls(new object[]{0, 0}) on a 3-column DataFrame, or FillNulls with a list built for a different schema version (columns added/removed earlier in the pipeline).","commonSituations":"Hardcoded filler arrays that drift from the schema; columns appended after the filler list was written; reusing one filler list across DataFrames with different column counts.","solutions":["Build the values list dynamically: df.Columns.Select(c => (object)fillerFor(c)).ToList() so its count always matches.","Assert values.Count == df.Columns.Count before the call and fail with your own clearer message.","Catch ArgumentException to report the expected vs supplied count.","If you only need one scalar for all columns, call df.FillNulls(object) (single-value overload) instead."],"exampleFix":"// before\ndf.FillNulls(new object[] { 0, \"none\" }); // 3 columns\n// after\nvar vals = df.Columns.Select(c => c.DataType == typeof(string) ? (object)\"none\" : 0).ToList();\ndf.FillNulls(vals);","handlingStrategy":"validation","validationCode":"if (values.Count != df.Columns.Count)\n    throw new ArgumentException($\"FillNulls needs {df.Columns.Count} values, got {values.Count}\");\ndf.FillNulls(values);","typeGuard":null,"tryCatchPattern":"try { df.FillNulls(values); }\ncatch (ArgumentException ex) { logger.LogError(ex, \"Filler count mismatch\"); throw; }","preventionTips":["Derive the filler list from df.Columns at call time, never hard-code it","Prefer the single-value FillNulls(object) overload when one filler fits all columns","Re-derive fillers whenever columns are added or dropped in the pipeline"],"tags":["argument","fillna","column-count","shape"],"backgroundTag":"argument-out-of-range","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"}