dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
9.02k stars 1.88k forks source link

Primitive DataFrame Column Clone method crashes with IEnumerable argument #6821

Closed asmirnov82 closed 1 year ago

asmirnov82 commented 1 year ago

public PrimitiveDataFrameColumn Clone(IEnumerable mapIndices) - crashes with System.ArgumentOutOfRangeException: 'rowIndex Parameter name: Index cannot be greater than the Column's Length' exception

Simple unti test:

[Fact]
public void TestNotNullableColumnCloneWithIndicesMapAsEnumerable()
{
    //Arrange
    var column = new Int32DataFrameColumn("Int column", values: new[] { 0, 5, 2, 4, 1, 3 });
    var indicesMap = new long[] { 0, 1, 2, 5, 3, 4 };

    //Act
    var clonedColumn = column.Clone(indicesMap);

    //Assert
    Assert.NotSame(column, clonedColumn);
    Assert.Equal(column.Name, clonedColumn.Name);
    Assert.Equal(column.DataType, clonedColumn.DataType);
    Assert.Equal(column.NullCount, clonedColumn.NullCount);
    Assert.Equal(indicesMap.Length, clonedColumn.Length);

    for (int i = 0; i < indicesMap.Length; i++)
        Assert.Equal(column[indicesMap[i]], clonedColumn[i]);
}