Skip to content

Enabled '_' in the field/column name in input type. #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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