diff --git a/src/Microsoft.Data.Analysis/DataFrameBuffer.cs b/src/Microsoft.Data.Analysis/DataFrameBuffer.cs index 352b853ddc..66abed3ba2 100644 --- a/src/Microsoft.Data.Analysis/DataFrameBuffer.cs +++ b/src/Microsoft.Data.Analysis/DataFrameBuffer.cs @@ -77,8 +77,9 @@ internal override T this[int index] { set { - if (index > Length) + if (index >= Length) throw new ArgumentOutOfRangeException(nameof(index)); + RawSpan[index] = value; } } diff --git a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs index 113b67cc1c..51058e529a 100644 --- a/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs +++ b/src/Microsoft.Data.Analysis/PrimitiveDataFrameColumn.cs @@ -164,7 +164,7 @@ protected internal override Apache.Arrow.Array ToArrowArray(long startIndex, int { get { - if (startIndex > Length) + if (startIndex >= Length) { throw new ArgumentOutOfRangeException(nameof(startIndex)); } @@ -174,7 +174,7 @@ protected internal override Apache.Arrow.Array ToArrowArray(long startIndex, int protected override IReadOnlyList GetValues(long startIndex, int length) { - if (startIndex > Length) + if (startIndex >= Length) { throw new ArgumentOutOfRangeException(nameof(startIndex)); } diff --git a/src/Microsoft.Data.Analysis/ReadOnlyDataFrameBuffer.cs b/src/Microsoft.Data.Analysis/ReadOnlyDataFrameBuffer.cs index 2bc41ebe51..b3a8a7bccf 100644 --- a/src/Microsoft.Data.Analysis/ReadOnlyDataFrameBuffer.cs +++ b/src/Microsoft.Data.Analysis/ReadOnlyDataFrameBuffer.cs @@ -66,8 +66,9 @@ internal virtual T this[int index] { get { - if (index > Length) + if (index >= Length) throw new ArgumentOutOfRangeException(nameof(index)); + return ReadOnlySpan[index]; } set => throw new NotSupportedException(); diff --git a/src/Microsoft.Data.Analysis/StringDataFrameColumn.cs b/src/Microsoft.Data.Analysis/StringDataFrameColumn.cs index 0d88ef5505..1a46ff74a9 100644 --- a/src/Microsoft.Data.Analysis/StringDataFrameColumn.cs +++ b/src/Microsoft.Data.Analysis/StringDataFrameColumn.cs @@ -77,7 +77,7 @@ public void Append(string value) private int GetBufferIndexContainingRowIndex(ref long rowIndex) { - if (rowIndex > Length) + if (rowIndex >= Length) { throw new ArgumentOutOfRangeException(Strings.ColumnIndexOutOfRange, nameof(rowIndex)); } diff --git a/src/Microsoft.Data.Analysis/VBufferDataFrameColumn.cs b/src/Microsoft.Data.Analysis/VBufferDataFrameColumn.cs index 35456f34c4..ee860cfa33 100644 --- a/src/Microsoft.Data.Analysis/VBufferDataFrameColumn.cs +++ b/src/Microsoft.Data.Analysis/VBufferDataFrameColumn.cs @@ -85,10 +85,11 @@ public void Append(VBuffer value) private int GetBufferIndexContainingRowIndex(ref long rowIndex) { - if (rowIndex > Length) + if (rowIndex >= Length) { throw new ArgumentOutOfRangeException(Strings.ColumnIndexOutOfRange, nameof(rowIndex)); } + return (int)(rowIndex / int.MaxValue); }