Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 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,8 @@ 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.");
if (!new CSharpCodeProvider().IsValidIdentifier(name))
throw Contracts.Except($"{name} is not a valid identifier.");

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