@@ -877,5 +877,48 @@ public void TestTextLoaderNoFields()
877877 Assert . StartsWith ( "Should define at least one public, readable field or property in TInput." , ex . Message ) ;
878878 }
879879 }
880+
881+ public class BreastCancerInputModelWithKeyType
882+ {
883+ [ LoadColumn ( 0 ) ]
884+ public bool IsMalignant { get ; set ; }
885+
886+ [ LoadColumn ( 1 ) , KeyType ( 10 ) ]
887+ public uint Thickness { get ; set ; }
888+ }
889+
890+ public class BreastCancerInputModelWithoutKeyType
891+ {
892+ [ LoadColumn ( 0 ) ]
893+ public bool IsMalignant { get ; set ; }
894+
895+ [ LoadColumn ( 1 ) ]
896+ public uint Thickness { get ; set ; }
897+ }
898+
899+ [ Fact ]
900+ public void TestLoadTextWithKeyTypeAttribute ( )
901+ {
902+ ulong expectedCount = 10 ;
903+
904+ var mlContext = new MLContext ( seed : 1 ) ;
905+ string breastCancerPath = GetDataPath ( TestDatasets . breastCancer . trainFilename ) ;
906+
907+ var data = mlContext . Data . CreateTextLoader < BreastCancerInputModelWithKeyType > ( separatorChar : ',' ) . Load ( breastCancerPath ) ;
908+
909+ Assert . Equal ( expectedCount , data . Schema [ 1 ] . Type . GetKeyCount ( ) ) ;
910+ }
911+
912+ [ Fact ]
913+ public void TestLoadTextWithoutKeyTypeAttribute ( )
914+ {
915+ ulong expectedCount = 0 ;
916+ var mlContext = new MLContext ( seed : 1 ) ;
917+ string breastCancerPath = GetDataPath ( TestDatasets . breastCancer . trainFilename ) ;
918+
919+ var data = mlContext . Data . CreateTextLoader < BreastCancerInputModelWithoutKeyType > ( separatorChar : ',' ) . Load ( breastCancerPath ) ;
920+
921+ Assert . Equal ( expectedCount , data . Schema [ 1 ] . Type . GetKeyCount ( ) ) ;
922+ }
880923 }
881924}
0 commit comments