Skip to content

Commit 76d43d4

Browse files
committed
Use index in the column passed in to access everything
1 parent dc57b22 commit 76d43d4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/Microsoft.ML.Data/Utilities/ColumnCursor.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ public static IEnumerable<T> GetColumn<T>(this IDataView data, DataViewSchema.Co
2626
Contracts.CheckValue(data, nameof(data));
2727
Contracts.CheckNonEmpty(column.Name, nameof(column));
2828

29-
if (!data.Schema.TryGetColumnIndex(column.Name, out int colIndex))
30-
throw Contracts.ExceptParam(nameof(column), string.Format("column name {0} cannot be found in {1}", column.Name, nameof(data)));
29+
var colIndex = column.Index;
30+
var colType = column.Type;
31+
var colName = column.Name;
3132

32-
if (data.Schema[colIndex].Type != column.Type)
33-
throw Contracts.ExceptParam(nameof(column), string.Format("column {0}'s type {1} doesn't match the expected type {2} in {3}",
34-
column.Name, column.Type, data.Schema[colIndex].Type, nameof(data)));
33+
// Use column index as the principle address of the specified input column and check if that address in data contains
34+
// the column indicated.
35+
if (data.Schema[colIndex].Name != colName || data.Schema[colIndex].Type != colType)
36+
throw Contracts.ExceptParam(nameof(column), string.Format("column with name {0}, type {1}, and index {2} cannot be found in {3}",
37+
colName, colType, colIndex, nameof(data)));
3538

3639
// There are two decisions that we make here:
3740
// - Is the T an array type?
@@ -41,7 +44,6 @@ public static IEnumerable<T> GetColumn<T>(this IDataView data, DataViewSchema.Co
4144
// - If this is the same type, we can map directly.
4245
// - Otherwise, we need a conversion delegate.
4346

44-
var colType = column.Type;
4547
if (colType.RawType == typeof(T))
4648
{
4749
// Direct mapping is possible.

0 commit comments

Comments
 (0)