Skip to content

Commit 87071c8

Browse files
committed
Robust Scalar fully working. Signed Native nuget included
1 parent 8f04d81 commit 87071c8

File tree

4 files changed

+445
-42
lines changed

4 files changed

+445
-42
lines changed

src/Microsoft.ML.Featurizers/RobustScalerTransformer.cs renamed to src/Microsoft.ML.Featurizers/RobustScaler.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ internal RobustScalerEstimator(IHostEnvironment env, Options options)
119119
Contracts.CheckValue(env, nameof(env));
120120
_host = env.Register(nameof(CategoryImputerTransformerEstimator));
121121
Contracts.Check(options.QuantileMin >= 0.0f && options.QuantileMin < options.QuantileMax && options.QuantileMax <= 100.0f, "Invalid QuantileRange provided");
122+
Contracts.CheckNonEmpty(options.Columns, nameof(options.Columns));
122123

123124
_options = options;
124125
}
@@ -135,6 +136,10 @@ public SchemaShape GetOutputSchema(SchemaShape inputSchema)
135136
foreach (var column in _options.Columns)
136137
{
137138
var inputColumn = columns[column.Source];
139+
140+
if (!RobustScalerTransformer.TypedColumn.IsColumnTypeSupported(inputColumn.ItemType.RawType))
141+
throw new InvalidOperationException($"Type {inputColumn.ItemType.RawType.ToString()} for column {column.Name} not a supported type.");
142+
138143
if (_floatTypes.Contains(inputColumn.ItemType.RawType))
139144
{
140145
columns[column.Name] = new SchemaShape.Column(column.Name, inputColumn.Kind,
@@ -336,6 +341,10 @@ internal abstract class TypedColumn : IDisposable
336341
internal readonly string Name;
337342
internal readonly string Source;
338343
internal readonly string Type;
344+
345+
private static readonly Type[] _supportedTypes = new[] { typeof(sbyte), typeof(short), typeof(int), typeof(long), typeof(byte), typeof(ushort),
346+
typeof(uint), typeof(ulong), typeof(float), typeof(double) };
347+
339348
internal TypedColumn(string name, string source, string type)
340349
{
341350
Name = name;
@@ -374,6 +383,11 @@ internal unsafe void CreateTransformerFromSavedData(byte[] data)
374383
}
375384
}
376385

386+
internal static bool IsColumnTypeSupported(Type type)
387+
{
388+
return _supportedTypes.Contains(type);
389+
}
390+
377391
internal static TypedColumn CreateTypedColumn(string name, string source, string type, RobustScalerTransformer parent)
378392
{
379393
if (type == typeof(sbyte).ToString())
@@ -417,7 +431,7 @@ internal static TypedColumn CreateTypedColumn(string name, string source, string
417431
return new DoubleTypedColumn(name, source, parent);
418432
}
419433

420-
throw new Exception($"Unsupported type {type}");
434+
throw new InvalidOperationException($"Column {name} has an unsupported type {type}.");
421435
}
422436
}
423437

12.2 MB
Binary file not shown.

test/Microsoft.ML.Tests/Transformers/RobustScalarTests.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)