forked from dotnet/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
InferColumns API: Validate all columns specified in column info exist…
… in inferred data view (dotnet#3599)
- Loading branch information
Showing
5 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/Microsoft.ML.Auto/ColumnInference/ColumnInferenceValidationUtil.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
|
||
namespace Microsoft.ML.Auto | ||
{ | ||
internal static class ColumnInferenceValidationUtil | ||
{ | ||
/// <summary> | ||
/// Validate all columns specified in column info exist in inferred data view. | ||
/// </summary> | ||
public static void ValidateSpecifiedColumnsExist(ColumnInformation columnInfo, | ||
IDataView dataView) | ||
{ | ||
var columnNames = ColumnInformationUtil.GetColumnNames(columnInfo); | ||
foreach (var columnName in columnNames) | ||
{ | ||
if (dataView.Schema.GetColumnOrNull(columnName) == null) | ||
{ | ||
throw new ArgumentException($"Specified column {columnName} " + | ||
$"is not found in the dataset."); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/Microsoft.ML.AutoML.Tests/ColumnInferenceValidationUtilTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.IO; | ||
using Microsoft.ML.Data; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Microsoft.ML.Auto.Test | ||
{ | ||
[TestClass] | ||
public class ColumnInferenceValidationUtilTests | ||
{ | ||
[TestMethod] | ||
[ExpectedException(typeof(ArgumentException))] | ||
public void ValidateColumnNotContainedInData() | ||
{ | ||
var schemaBuilder = new DataViewSchema.Builder(); | ||
schemaBuilder.AddColumn(DefaultColumnNames.Features, NumberDataViewType.Single); | ||
schemaBuilder.AddColumn(DefaultColumnNames.Label, NumberDataViewType.Single); | ||
var schema = schemaBuilder.ToSchema(); | ||
var dataView = new EmptyDataView(new MLContext(), schema); | ||
var columnInfo = new ColumnInformation(); | ||
columnInfo.CategoricalColumnNames.Add("Categorical"); | ||
ColumnInferenceValidationUtil.ValidateSpecifiedColumnsExist(columnInfo, dataView); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters