Skip to content

Commit a0deda0

Browse files
artidoroTomFinley
authored andcommitted
Fix TextLoader version number for KeyType backward compatibility and added new test (#2295)
* adding test for backcompat * changed model file
1 parent 8c0a111 commit a0deda0

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/Microsoft.ML.Data/DataLoadSave/Text/TextLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,7 @@ private Schema ComputeOutputSchema()
908908
public const string LoaderSignature = "TextLoader";
909909

910910
private const uint VerForceVectorSupported = 0x0001000A;
911-
private const uint VersionNoMinCount = 0x00010004;
911+
private const uint VersionNoMinCount = 0x0001000C;
912912

913913
private static VersionInfo GetVersionInfo()
914914
{

test/Microsoft.ML.Tests/TextLoaderTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.Data.DataView;
99
using Microsoft.ML.Data;
1010
using Microsoft.ML.EntryPoints.JsonUtils;
11+
using Microsoft.ML.Model;
1112
using Microsoft.ML.RunTests;
1213
using Microsoft.ML.TestFramework;
1314
using Microsoft.ML.Transforms.Conversions;
@@ -770,5 +771,23 @@ public void LoaderColumnsFromIrisData()
770771
irisFirstRowValues.MoveNext(); irisFirstRowValues.MoveNext(); // skip col 1
771772
Assert.Equal(vals4[1], irisFirstRowValues.Current);
772773
}
774+
775+
[Fact]
776+
public void TestTextLoaderKeyTypeBackCompat()
777+
{
778+
// Model generated with the following command on a version of the code previous to the KeyType change that removed Min and Contiguous:
779+
// Train data=...\breast-cancer.txt loader =TextLoader{col=Label:R4:0 col=Features:R4:1-9 col=key:U4[0-*]:3} tr=LogisticRegression {} out=model.zip
780+
var mlContext = new MLContext();
781+
string textLoaderModelPath = GetDataPath("backcompat/textloader-with-key-model.zip");
782+
string breastCancerPath = GetDataPath(TestDatasets.breastCancer.trainFilename);
783+
784+
using (FileStream modelfs = File.OpenRead(textLoaderModelPath))
785+
using (var rep = RepositoryReader.Open(modelfs, mlContext))
786+
{
787+
var result = ModelFileUtils.LoadLoader(mlContext, rep, new MultiFileSource(breastCancerPath), false);
788+
Assert.True(result.Schema.TryGetColumnIndex("key", out int featureIdx));
789+
Assert.True(result.Schema[featureIdx].Type is KeyType keyType && keyType.Count == typeof(uint).ToMaxInt());
790+
}
791+
}
773792
}
774793
}
Binary file not shown.

0 commit comments

Comments
 (0)