@@ -26,12 +26,15 @@ public static IEnumerable<T> GetColumn<T>(this IDataView data, DataViewSchema.Co
26
26
Contracts . CheckValue ( data , nameof ( data ) ) ;
27
27
Contracts . CheckNonEmpty ( column . Name , nameof ( column ) ) ;
28
28
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 ;
31
32
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 ) ) ) ;
35
38
36
39
// There are two decisions that we make here:
37
40
// - Is the T an array type?
@@ -41,7 +44,6 @@ public static IEnumerable<T> GetColumn<T>(this IDataView data, DataViewSchema.Co
41
44
// - If this is the same type, we can map directly.
42
45
// - Otherwise, we need a conversion delegate.
43
46
44
- var colType = column . Type ;
45
47
if ( colType . RawType == typeof ( T ) )
46
48
{
47
49
// Direct mapping is possible.
0 commit comments