From 9cc1c3d324f7807ae974b91691f196ee5940dc2e Mon Sep 17 00:00:00 2001 From: Abhishek Goswami Date: Mon, 3 Jun 2019 19:17:11 +0000 Subject: [PATCH] check for number of input columns in concat transform --- .../ColumnConcatenatingEstimator.cs | 1 + .../Transformers/ConcatTests.cs | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/Microsoft.ML.Data/Transforms/ColumnConcatenatingEstimator.cs b/src/Microsoft.ML.Data/Transforms/ColumnConcatenatingEstimator.cs index 02146d1c4e..a7784d1875 100644 --- a/src/Microsoft.ML.Data/Transforms/ColumnConcatenatingEstimator.cs +++ b/src/Microsoft.ML.Data/Transforms/ColumnConcatenatingEstimator.cs @@ -54,6 +54,7 @@ internal ColumnConcatenatingEstimator(IHostEnvironment env, string outputColumnN _host.CheckNonEmpty(outputColumnName, nameof(outputColumnName)); _host.CheckValue(inputColumnNames, nameof(inputColumnNames)); + _host.CheckParam(inputColumnNames.Length > 0, nameof(inputColumnNames), "Input columns not specified"); _host.CheckParam(!inputColumnNames.Any(r => string.IsNullOrEmpty(r)), nameof(inputColumnNames), "Contained some null or empty items"); diff --git a/test/Microsoft.ML.Tests/Transformers/ConcatTests.cs b/test/Microsoft.ML.Tests/Transformers/ConcatTests.cs index 098a10a541..ee652d1597 100644 --- a/test/Microsoft.ML.Tests/Transformers/ConcatTests.cs +++ b/test/Microsoft.ML.Tests/Transformers/ConcatTests.cs @@ -2,6 +2,7 @@ // 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.ML.Data.IO; @@ -17,6 +18,25 @@ public ConcatTests(ITestOutputHelper output) : base(output) { } + [Fact] + void TestConcatNoInputColumns() + { + var thrown = false; + + try + { + var pipe = ML.Transforms.Concatenate("Features"); + } + catch(Exception ex) + { + Assert.Contains("Input columns not specified", ex.Message); + thrown = true; + + } + Assert.True(thrown); + Done(); + } + [Fact] void TestConcat() {