Skip to content

DataFrame IndexOufRange exception on attemp to call Apply method #7122

Closed as not planned

Description

@asmirnov82

Test to reproduce:

public void TestApplyMethod()
{
    PrimitiveDataFrameColumn<byte> column = new PrimitiveDataFrameColumn<byte>("Byte1", int.MaxValue / 2 - 1);
    PrimitiveDataFrameColumn<double> newColumn = column.Apply<double>(x => (double?)x);
}

Root cause is in Apply method:

public void Apply<TResult>(Func<T?, TResult?> func, PrimitiveColumnContainer<TResult> resultContainer)
    where TResult : unmanaged
{
    for (int b = 0; b < Buffers.Count; b++)
    {
        var sourceBuffer = Buffers[b];
        var sourceNullBitMap = NullBitMapBuffers[b].ReadOnlySpan;

        Span<TResult> mutableResultBuffer = resultContainer.Buffers.GetOrCreateMutable(b).Span;
        Span<byte> mutableResultNullBitMapBuffers = resultContainer.NullBitMapBuffers.GetOrCreateMutable(b).Span;

        for (int i = 0; i < sourceBuffer.Length; i++)
        {
            bool isValid = BitUtility.IsValid(sourceNullBitMap, i);
            TResult? value = func(isValid ? sourceBuffer[i] : null);
            mutableResultBuffer[i] = value.GetValueOrDefault();
            resultContainer.SetValidityBit(mutableResultNullBitMapBuffers, i, value != null);
        }
    }
}

mutableResultBuffer has TResult type of underlying data, so it's max length is 2Gb / sizeof(TResult)
sourceBuffer has T type of underlying data, so it's max length is 2 Gb/ sizeof(T)

when sizeof(TResult) > sizeof(T) and source buffer is large enough - it resulted in IndexOutOfRange exception

Activity

  1. rosebyte commented on Sep 24, 2026

    @rosebyte
    Member

    Triage: it might be a bug, we will take a look.

  2. added
    bugSomething isn't working
    and removed
    untriagedNew issue has not been triaged
    on Sep 24, 2026
  3. added this to the ML.NET Future milestone on Sep 24, 2026
  4. vejbomar commented on Oct 16, 2026

    @vejbomar
    Contributor

    The method is deprecated, so we decided not to do the changes here. #7763 contains example of how the new API can be used to achieve the cross-type Apply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-DataFrameMicrosoft.Data.Analysis DataFrame APIsbugSomething isn't workingyellowmaintenance only

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions