diff --git a/src/Microsoft.ML.Transforms/NAReplaceTransform.cs b/src/Microsoft.ML.Transforms/NAReplaceTransform.cs index 522237e303..52989472fc 100644 --- a/src/Microsoft.ML.Transforms/NAReplaceTransform.cs +++ b/src/Microsoft.ML.Transforms/NAReplaceTransform.cs @@ -43,6 +43,7 @@ public enum ReplacementKind Mean, Minimum, Maximum, + SpecifiedValue, [HideEnumValue] Def = DefaultValue, @@ -53,8 +54,6 @@ public enum ReplacementKind [HideEnumValue] Max = Maximum, - [HideEnumValue] - SpecifiedValue, [HideEnumValue] Val = SpecifiedValue, [HideEnumValue] diff --git a/src/Microsoft.ML/CSharpApi.cs b/src/Microsoft.ML/CSharpApi.cs index e943e76bca..05edec3cd9 100644 --- a/src/Microsoft.ML/CSharpApi.cs +++ b/src/Microsoft.ML/CSharpApi.cs @@ -11058,14 +11058,10 @@ namespace Transforms { public enum NAHandleTransformReplacementKind { - Default = 0, - Def = 0, DefaultValue = 0, Mean = 1, Minimum = 2, - Min = 2, - Maximum = 3, - Max = 3 + Maximum = 3 } @@ -11153,7 +11149,7 @@ public void AddColumn(string outputColumn, string inputColumn) /// /// The replacement method to utilize /// - public NAHandleTransformReplacementKind ReplaceWith { get; set; } = NAHandleTransformReplacementKind.Def; + public NAHandleTransformReplacementKind ReplaceWith { get; set; } = NAHandleTransformReplacementKind.DefaultValue; /// /// Whether to impute values by slot @@ -11527,17 +11523,11 @@ namespace Transforms { public enum NAReplaceTransformReplacementKind { - Default = 0, DefaultValue = 0, - Def = 0, Mean = 1, - Min = 2, Minimum = 2, - Max = 3, Maximum = 3, - SpecifiedValue = 4, - Val = 4, - Value = 4 + SpecifiedValue = 4 } @@ -11625,7 +11615,7 @@ public void AddColumn(string outputColumn, string inputColumn) /// /// The replacement method to utilize /// - public NAReplaceTransformReplacementKind ReplacementKind { get; set; } = NAReplaceTransformReplacementKind.Def; + public NAReplaceTransformReplacementKind ReplacementKind { get; set; } = NAReplaceTransformReplacementKind.DefaultValue; /// /// Whether to impute values by slot diff --git a/src/Microsoft.ML/Runtime/EntryPoints/JsonUtils/JsonManifestUtils.cs b/src/Microsoft.ML/Runtime/EntryPoints/JsonUtils/JsonManifestUtils.cs index 7950975a22..fd76ad8565 100644 --- a/src/Microsoft.ML/Runtime/EntryPoints/JsonUtils/JsonManifestUtils.cs +++ b/src/Microsoft.ML/Runtime/EntryPoints/JsonUtils/JsonManifestUtils.cs @@ -344,7 +344,7 @@ private static JToken BuildTypeToken(IExceptionContext ectx, FieldInfo fieldInfo case TlcModule.DataKind.Enum: jo = new JObject(); jo[FieldNames.Kind] = typeEnum.ToString(); - var values = Enum.GetNames(type); + var values = Enum.GetNames(type).Where(n => type.GetField(n).GetCustomAttribute() == null); jo[FieldNames.Values] = new JArray(values); return jo; case TlcModule.DataKind.Array: diff --git a/src/Microsoft.ML/Runtime/Internal/Tools/CSharpApiGenerator.cs b/src/Microsoft.ML/Runtime/Internal/Tools/CSharpApiGenerator.cs index ad714a4998..db7c1d490d 100644 --- a/src/Microsoft.ML/Runtime/Internal/Tools/CSharpApiGenerator.cs +++ b/src/Microsoft.ML/Runtime/Internal/Tools/CSharpApiGenerator.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Reflection; using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.CommandLine; using Microsoft.ML.Runtime.Data; @@ -156,6 +157,8 @@ private void GenerateEnums(IndentingTextWriter writer, Type inputType, string cu for (int i = 0; i < names.Length; i++) { var name = names[i]; + if (type.GetField(name).GetCustomAttribute() != null) + continue; var value = values.GetValue(i); writer.WriteLine(prefix); if (enumType == typeof(int)) diff --git a/src/Microsoft.ML/Runtime/Internal/Tools/CSharpGeneratorUtils.cs b/src/Microsoft.ML/Runtime/Internal/Tools/CSharpGeneratorUtils.cs index fc9fabb758..cca73a21f9 100644 --- a/src/Microsoft.ML/Runtime/Internal/Tools/CSharpGeneratorUtils.cs +++ b/src/Microsoft.ML/Runtime/Internal/Tools/CSharpGeneratorUtils.cs @@ -6,6 +6,7 @@ using System.CodeDom; using System.Collections.Generic; using System.Linq; +using System.Reflection; using Microsoft.CSharp; using Microsoft.ML.Runtime.CommandLine; using Microsoft.ML.Runtime.EntryPoints; @@ -279,10 +280,22 @@ public static string GetValue(ModuleCatalog catalog, Type fieldType, object fiel case TlcModule.DataKind.Bool: return (bool)fieldValue ? "true" : "false"; case TlcModule.DataKind.Enum: + string enumAsString = fieldValue.ToString(); + if (fieldType.GetField(enumAsString).GetCustomAttribute() != null) + { + // The default value for the enum has the hiding attribute on it. We will search for + // alternate names. Regrettably I see no way beyond a manual scan. + + string unhiddenName = Enum.GetNames(fieldType).Zip(Enum.GetValues(fieldType).Cast(), (name, val) => (name, val)) + .Where(pair => pair.val.Equals(fieldValue)) + .Where(pair => fieldType.GetField(pair.name).GetCustomAttribute() == null) + .Select(pair => pair.name).FirstOrDefault(); + enumAsString = unhiddenName ?? throw Contracts.Except($"Could not find unhidden alternative for '{fieldValue}' in type '{fieldType}'"); + } if (generatedClasses.IsGenerated(fieldType.FullName)) - return generatedClasses.GetApiName(fieldType, rootNameSpace) + "." + fieldValue; + return generatedClasses.GetApiName(fieldType, rootNameSpace) + "." + enumAsString; else - return generatedClasses.GetApiName(fieldType, "Runtime") + "." + fieldValue; + return generatedClasses.GetApiName(fieldType, "Runtime") + "." + enumAsString; case TlcModule.DataKind.Char: return $"'{GetCharAsString((char)fieldValue)}'"; case TlcModule.DataKind.Component: diff --git a/test/BaselineOutput/Common/EntryPoints/core_manifest.json b/test/BaselineOutput/Common/EntryPoints/core_manifest.json index ea1a86a2e8..02cfd2c0c7 100644 --- a/test/BaselineOutput/Common/EntryPoints/core_manifest.json +++ b/test/BaselineOutput/Common/EntryPoints/core_manifest.json @@ -15390,14 +15390,10 @@ "Type": { "Kind": "Enum", "Values": [ - "Default", - "Def", "DefaultValue", "Mean", "Minimum", - "Min", - "Maximum", - "Max" + "Maximum" ] }, "Desc": "The replacement method to utilize", @@ -15478,14 +15474,10 @@ "Type": { "Kind": "Enum", "Values": [ - "Default", - "Def", "DefaultValue", "Mean", "Minimum", - "Min", - "Maximum", - "Max" + "Maximum" ] }, "Desc": "The replacement method to utilize", @@ -15780,17 +15772,11 @@ "Type": { "Kind": "Enum", "Values": [ - "Default", "DefaultValue", - "Def", "Mean", - "Min", "Minimum", - "Max", "Maximum", - "SpecifiedValue", - "Val", - "Value" + "SpecifiedValue" ] }, "Desc": "The replacement method to utilize", @@ -15856,17 +15842,11 @@ "Type": { "Kind": "Enum", "Values": [ - "Default", "DefaultValue", - "Def", "Mean", - "Min", "Minimum", - "Max", "Maximum", - "SpecifiedValue", - "Val", - "Value" + "SpecifiedValue" ] }, "Desc": "The replacement method to utilize", @@ -15876,7 +15856,7 @@ "Required": false, "SortOrder": 150.0, "IsNullable": false, - "Default": "Def" + "Default": "Default" }, { "Name": "ImputeBySlot",