{"record":{"id":"866b61a17df3bc55","repo":"dotnet/machinelearning","slug":"row","errorCode":null,"errorMessage":"row","messagePattern":"row","errorType":"exception","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs","lineNumber":914,"sourceCode":"\n        protected internal override void AddValueUsingCursor(DataViewRowCursor cursor, Delegate getter)\n        {\n            long row = cursor.Position;\n            T value = default;\n            Debug.Assert(getter != null, \"Excepted getter to be valid\");\n            (getter as ValueGetter<T>)(ref value);\n\n            if (Length > row)\n            {\n                this[row] = value;\n            }\n            else if (Length == row)\n            {\n                Append(value);\n            }\n            else\n            {\n                throw new IndexOutOfRangeException(nameof(row));\n            }\n        }\n\n        protected internal override Delegate GetValueGetterUsingCursor(DataViewRowCursor cursor, DataViewSchema.Column schemaColumn)\n        {\n            return cursor.GetGetter<T>(schemaColumn);\n        }\n\n        public override Dictionary<long, ICollection<long>> GetGroupedOccurrences(DataFrameColumn other, out HashSet<long> otherColumnNullIndices)\n        {\n            return GetGroupedOccurrences<T>(other, out otherColumnNullIndices);\n        }\n\n        public override PrimitiveDataFrameColumn<bool> ElementwiseIsNull()\n        {\n            var ret = new BooleanDataFrameColumn(Name, Length);\n\n            for (long i = 0; i < Length; i++)","sourceCodeStart":896,"sourceCodeEnd":932,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs#L896-L932","documentation":"PrimitiveDataFrameColumn<T>.ApplyElementwise (the indexer-style setter) only allows writing at positions already occupied or exactly at the end. If the given row index is greater than the current Length, the column cannot sparse-fill the gap, so it throws IndexOutOfRangeException naming the 'row' parameter.","triggerScenarios":"Calling an element-wise apply/set API (e.g. ApplyElementwise or the column setter used by DataFrame row assignment) with a row index > column.Length, i.e. attempting to append beyond the end instead of exactly at Length.","commonSituations":"Building a column by assigning at computed indices after rows were dropped or filtered (Length shrank); misaligned row counters between two columns; off-by-one when the loop counter starts at Length instead of ending at it.","solutions":["Ensure the write index is < column.Length, or exactly == Length to append","Grow the column first by calling Append(value) for each missing row before random writes","Re-derive the row index from the DataFrame/cursor being iterated rather than a stale counter","Use DataFrameColumn length checks (index >= Length) in the callback and skip or extend accordingly"],"exampleFix":"// before\ncol[row] = value; // row > col.Length -> IndexOutOfRangeException\n// after\nif (row == col.Length) col.Append(value);\nelse if (row < col.Length) col[row] = value;","handlingStrategy":"validation","validationCode":"if (row < 0 || row > column.Length)\n    throw new ArgumentOutOfRangeException(nameof(row), $\"row {row} is outside [0, {column.Length}]; only == Length appends are allowed\");","typeGuard":"bool IsValidRow(PrimitiveDataFrameColumn<T> col, long row) => row >= 0 && row <= col.Length;","tryCatchPattern":"try\n{\n    column[row] = value;\n}\ncatch (IndexOutOfRangeException ex)\n{\n    // log ex.Message ('row') and clamp/append instead\n}","preventionTips":["Check row index against column.Length before every random write","Only write at Length to append; use Append explicitly","Recompute indices after any filter/drop that changes column Length"],"tags":["dataframe","index-out-of-range","dotnet"],"backgroundTag":"index-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"}