Skip to content

Commit

Permalink
Removed field/column name checking of input type in TextLoader. (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeahmed authored Jun 11, 2018
1 parent d1a350f commit 45ced36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/Microsoft.ML/Data/TextLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 Microsoft.CSharp;
using Microsoft.ML.Runtime;
using Microsoft.ML.Runtime.Api;
using Microsoft.ML.Runtime.Data;
Expand Down Expand Up @@ -84,8 +85,6 @@ public TextLoader CreateFrom<TInput>(bool useHeader = false,
$"Valid characters are 0-9, *, - and ~");

var name = mappingAttr.Name ?? field.Name;
if (name.Any(c => !Char.IsLetterOrDigit(c)))
throw Contracts.Except($"{name} is not alphanumeric.");

Runtime.Data.TextLoader.Range[] sources;
if (!Runtime.Data.TextLoader.Column.TryParseSourceEx(mappingAttr.Ordinal, out sources))
Expand Down
12 changes: 12 additions & 0 deletions test/Microsoft.ML.Tests/TextLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ public void ConstructorDoesntThrow()
Assert.NotNull(new Data.TextLoader("fakeFile.txt").CreateFrom<Input>(useHeader: false, supportSparse: false, trimWhitespace: false));
Assert.NotNull(new Data.TextLoader("fakeFile.txt").CreateFrom<Input>(useHeader: false, supportSparse: false));
Assert.NotNull(new Data.TextLoader("fakeFile.txt").CreateFrom<Input>(useHeader: false, allowQuotedStrings: false));

Assert.NotNull(new Data.TextLoader("fakeFile.txt").CreateFrom<InputWithUnderscore>());
}


[Fact]
public void CanSuccessfullyApplyATransform()
{
Expand Down Expand Up @@ -264,6 +267,15 @@ public class Input
public float Number1;
}

public class InputWithUnderscore
{
[Column("0")]
public string String_1;

[Column("1")]
public float Number_1;
}

public class ModelWithoutColumnAttribute
{
public string String1;
Expand Down

0 comments on commit 45ced36

Please sign in to comment.