diff --git a/src/Microsoft.ML.Data/DataLoadSave/Text/TextLoader.cs b/src/Microsoft.ML.Data/DataLoadSave/Text/TextLoader.cs index 9caf93c626..14eb918779 100644 --- a/src/Microsoft.ML.Data/DataLoadSave/Text/TextLoader.cs +++ b/src/Microsoft.ML.Data/DataLoadSave/Text/TextLoader.cs @@ -1288,12 +1288,9 @@ private static bool TryParseSchema(IHost host, IMultiStreamSource files, ch.Assert(h.Loader == null || h.Loader is ICommandLineComponentFactory); var loader = h.Loader as ICommandLineComponentFactory; - if (loader == null || string.IsNullOrWhiteSpace(loader.Name)) - goto LDone; - - // Make sure the loader binds to us. - var info = host.ComponentCatalog.GetLoadableClassInfo(loader.Name); - if (info.Type != typeof(ILegacyDataLoader) || info.ArgType != typeof(Options)) + // Make sure that the schema is described using either the syntax TextLoader{} or the syntax Text{}, + // where "settings" is a string that can be parsed by CmdParser into an object of type TextLoader.Options. + if (loader == null || string.IsNullOrWhiteSpace(loader.Name) || (loader.Name != LoaderSignature && loader.Name != "Text")) goto LDone; var optionsNew = new Options(); diff --git a/test/Microsoft.ML.Tests/TextLoaderTests.cs b/test/Microsoft.ML.Tests/TextLoaderTests.cs index 8ef41ab3a3..7b96a8ab2e 100644 --- a/test/Microsoft.ML.Tests/TextLoaderTests.cs +++ b/test/Microsoft.ML.Tests/TextLoaderTests.cs @@ -598,6 +598,19 @@ public void ThrowsExceptionWithPropertyName() catch (NullReferenceException) { }; } + [Fact] + public void ParseSchemaFromTextFile() + { + var mlContext = new MLContext(seed: 1); + var fileName = GetDataPath(TestDatasets.adult.trainFilename); + var loader = mlContext.Data.CreateTextLoader(new TextLoader.Options(), new MultiFileSource(fileName)); + var data = loader.Load(new MultiFileSource(fileName)); + Assert.NotNull(data.Schema.GetColumnOrNull("Label")); + Assert.NotNull(data.Schema.GetColumnOrNull("Workclass")); + Assert.NotNull(data.Schema.GetColumnOrNull("Categories")); + Assert.NotNull(data.Schema.GetColumnOrNull("NumericFeatures")); + } + public class QuoteInput { [LoadColumn(0)]