Skip to content

Commit 45ced36

Browse files
authored
Removed field/column name checking of input type in TextLoader. (#327)
1 parent d1a350f commit 45ced36

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Microsoft.ML/Data/TextLoader.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using Microsoft.CSharp;
56
using Microsoft.ML.Runtime;
67
using Microsoft.ML.Runtime.Api;
78
using Microsoft.ML.Runtime.Data;
@@ -84,8 +85,6 @@ public TextLoader CreateFrom<TInput>(bool useHeader = false,
8485
$"Valid characters are 0-9, *, - and ~");
8586

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

9089
Runtime.Data.TextLoader.Range[] sources;
9190
if (!Runtime.Data.TextLoader.Column.TryParseSourceEx(mappingAttr.Ordinal, out sources))

test/Microsoft.ML.Tests/TextLoaderTests.cs

+12
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ public void ConstructorDoesntThrow()
3232
Assert.NotNull(new Data.TextLoader("fakeFile.txt").CreateFrom<Input>(useHeader: false, supportSparse: false, trimWhitespace: false));
3333
Assert.NotNull(new Data.TextLoader("fakeFile.txt").CreateFrom<Input>(useHeader: false, supportSparse: false));
3434
Assert.NotNull(new Data.TextLoader("fakeFile.txt").CreateFrom<Input>(useHeader: false, allowQuotedStrings: false));
35+
36+
Assert.NotNull(new Data.TextLoader("fakeFile.txt").CreateFrom<InputWithUnderscore>());
3537
}
3638

39+
3740
[Fact]
3841
public void CanSuccessfullyApplyATransform()
3942
{
@@ -264,6 +267,15 @@ public class Input
264267
public float Number1;
265268
}
266269

270+
public class InputWithUnderscore
271+
{
272+
[Column("0")]
273+
public string String_1;
274+
275+
[Column("1")]
276+
public float Number_1;
277+
}
278+
267279
public class ModelWithoutColumnAttribute
268280
{
269281
public string String1;

0 commit comments

Comments
 (0)