dotnet/machinelearning · error · ArgumentOutOfRangeException

Strings.IndexIsGreaterThanColumnLength

Error message

Strings.IndexIsGreaterThanColumnLength

What it means

GetBufferIndexContainingRowIndex locates which internal buffer holds a given row and throws ArgumentOutOfRangeException(Strings.IndexIsGreaterThanColumnLength, nameof(rowIndex)) when rowIndex >= Length. Note the arguments are swapped, so the exception message shows the library's message text rather than the parameter name. ArrowStringDataFrameColumn stores data across multiple buffers, and every per-row access funnels through this method.

Source

Thrown at src/Microsoft.Data.Analysis/DataFrameColumns/ArrowStringDataFrameColumn.cs:224

                    _nullBitMapBuffers.Add(new DataFrameBuffer<byte>());
                    mutableOffsetsBuffer = new DataFrameBuffer<int>();
                    _offsetsBuffers.Add(mutableOffsetsBuffer);
                    mutableOffsetsBuffer.Append(0);
                }
                var startIndex = mutableDataBuffer.Length;
                mutableDataBuffer.IncreaseSize(value.Length);
                value.CopyTo(mutableDataBuffer.RawSpan.Slice(startIndex));
                mutableOffsetsBuffer.Append(mutableOffsetsBuffer[mutableOffsetsBuffer.Length - 1] + value.Length);
            }
            SetValidityBit(Length - 1, !value.IsEmpty);

        }

        private int GetBufferIndexContainingRowIndex(long rowIndex, out int indexInBuffer)
        {
            if (rowIndex >= Length)
            {
                throw new ArgumentOutOfRangeException(Strings.IndexIsGreaterThanColumnLength, nameof(rowIndex));
            }

            // Since the strings here could be of variable length, scan linearly
            int curArrayIndex = 0;
            int numBuffers = _offsetsBuffers.Count;
            while (curArrayIndex < numBuffers && rowIndex > _offsetsBuffers[curArrayIndex].Length - 1)
            {
                rowIndex -= _offsetsBuffers[curArrayIndex].Length - 1;
                curArrayIndex++;
            }
            indexInBuffer = (int)rowIndex;
            return curArrayIndex;
        }

        private ReadOnlySpan<byte> GetBytes(long index)
        {
            int offsetsBufferIndex = GetBufferIndexContainingRowIndex(index, out int indexInBuffer);
            ReadOnlySpan<int> offsetBufferSpan = _offsetsBuffers[offsetsBufferIndex].ReadOnlySpan;

View on GitHub (pinned to 7b76e69cf9)

Solutions

  1. Validate rowIndex < column.Length before access and clamp or throw a domain-specific error.
  2. Re-read column.Length at loop time instead of caching it.
  3. Check how the column was constructed (Clone(numberOfNullsToAppend), buffers) if it is shorter than expected.
  4. If the swapped message text appears ('Index is greater than column length'), still treat it as an index-bounds problem on rowIndex.

Example fix

// before
var v = arrowCol[someRow.Index]; // someRow from a longer frame

// after
if (someRow.Index < arrowCol.Length)
    var v = arrowCol[someRow.Index];
Defensive patterns

Strategy: validation

Validate before calling

if (rowIndex < 0 || rowIndex >= column.Length)
    throw new ArgumentOutOfRangeException(nameof(rowIndex), "Index is greater than column length");

Type guard

static bool HasRow(ArrowStringDataFrameColumn c, long i) => i >= 0 && i < c.Length;

Try / catch

try { var v = column[rowIndex]; }
catch (ArgumentOutOfRangeException) { /* handle missing row: use default or skip */ }

Prevention

When it happens

Trigger: Any row access (indexer, GetValue, GetValues, ToArrowArray with startIndex) at or beyond the column's Length — e.g. reading index == Length, iterating with stale length, or passing a row index from a parent DataFrame whose row count exceeds this column.

Common situations: Ragged columns after Clone/append with fewer rows than expected; using DataFrame.Rows.Count on a column that was created shorter; loops bounded by a cached length captured before the column changed.

Related errors


AI-assisted analysis of dotnet/machinelearning@7b76e69cf9 (2026-09-11). Data as JSON: /api/errors/296968b045568157. Report an issue: GitHub.