Skip to content

Commit

Permalink
Throw error on incorrect Label name in InferColumns API (#47)
Browse files Browse the repository at this point in the history
* Added sequential grouping of columns

* reverted the file

* addded infer columns label name checking

* added column detection error

* removed unsed usings

* added quotes

* replace Where with Any clause

* replace Where with Any clause
  • Loading branch information
srsaggam authored Jan 30, 2019
1 parent bd900ff commit d254f4e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/AutoML/ColumnInference/ColumnInferenceApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public static ColumnInferenceResult InferColumns(MLContext context, string path,
var splitInference = InferSplit(sample, separatorChar, allowQuotedStrings, supportSparse);
var typeInference = InferColumnTypes(context, sample, splitInference, hasHeader);
var loaderColumns = ColumnTypeInference.GenerateLoaderColumns(typeInference.Columns);
if (!loaderColumns.Any(t => label.Equals(t.Name)))
{
throw new InferenceException(InferenceType.Label, $"Specified Label Column '{label}' was not found.");
}
var typedLoaderArgs = new TextLoader.Arguments
{
Column = loaderColumns,
Expand Down
8 changes: 8 additions & 0 deletions src/Test/ColumnInferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,13 @@ public void UnGroupColumnsTest()
var columnInferenceWithGrouping = context.Data.InferColumns(dataPath, DatasetUtil.UciAdultLabel, true, groupColumns: true);
Assert.IsTrue(columnInferenceWithGrouping.Columns.Count() < columnInferenceWithoutGrouping.Columns.Count());
}

[TestMethod]
public void IncorrectLabelColumnTest()
{
var dataPath = DatasetUtil.DownloadUciAdultDataset();
var context = new MLContext();
Assert.ThrowsException<InferenceException>(new System.Action(() => context.Data.InferColumns(dataPath, "Junk", true, groupColumns: false)));
}
}
}

0 comments on commit d254f4e

Please sign in to comment.