Skip to content

Commit 254304f

Browse files
committed
made existing ExceptSchemaMismatch more consistent
1 parent 9e74880 commit 254304f

37 files changed

+60
-60
lines changed

src/Microsoft.ML.Data/DataLoadSave/DataOperationsCatalog.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public IDataView FilterByKeyColumnFraction(IDataView input, string columnName, d
8686

8787
var type = input.Schema[columnName].Type;
8888
if (type.GetKeyCount() == 0)
89-
throw Environment.ExceptSchemaMismatch(nameof(columnName), "filter", columnName, "a key", type.ToString());
89+
throw Environment.ExceptSchemaMismatch(nameof(columnName), "filter", columnName, "KeyType", type.ToString());
9090
return new RangeFilter(Environment, input, columnName, lowerBound, upperBound, false);
9191
}
9292
}

src/Microsoft.ML.Data/Evaluators/AnomalyDetectionEvaluator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
9999
Host.Check(schema.Label.HasValue, "Could not find the label column");
100100
t = schema.Label.Value.Type;
101101
if (t != NumberType.Float && t.GetKeyCount() != 2)
102-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float or a 2-value key", t.ToString());
102+
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float or a 2-value KeyType", t.ToString());
103103
}
104104

105105
private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)

src/Microsoft.ML.Data/Evaluators/BinaryClassifierEvaluator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
132132
host.Check(schema.Label.HasValue, "Could not find the label column");
133133
t = schema.Label.Value.Type;
134134
if (t != NumberType.R4 && t != NumberType.R8 && t != BoolType.Instance && t.GetKeyCount() != 2)
135-
throw host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float, double, bool, or a 2-value key", t.ToString());
135+
throw host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float, double, bool, or a 2-value KeyType", t.ToString());
136136
}
137137

138138
private protected override void CheckCustomColumnTypesCore(RoleMappedSchema schema)
@@ -1097,7 +1097,7 @@ private void CheckInputColumnTypes(Schema schema)
10971097

10981098
var t = schema[(int) LabelIndex].Type;
10991099
if (t != NumberType.R4 && t != NumberType.R8 && t != BoolType.Instance && t.GetKeyCount() != 2)
1100-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "float, double, bool or a 2-value key", t.ToString());
1100+
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "float, double, bool or a 2-value KeyType", t.ToString());
11011101

11021102
t = schema[ScoreIndex].Type;
11031103
if (t != NumberType.Float)

src/Microsoft.ML.Data/Evaluators/MultiClassClassifierEvaluator.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
7676
var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
7777
var scoreType = score.Type as VectorType;
7878
if (scoreType == null || scoreType.Size < 2 || scoreType.ItemType != NumberType.Float)
79-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "vector of two or more items of type R4", scoreType.ToString());
79+
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "vector of two or more items of type float", scoreType.ToString());
8080
Host.CheckParam(schema.Label.HasValue, nameof(schema), "Could not find the label column");
8181
var labelType = schema.Label.Value.Type;
8282
if (labelType != NumberType.Float && labelType.GetKeyCount() <= 0)
83-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float or a known-cardinality key", labelType.ToString());
83+
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float or KeyType", labelType.ToString());
8484
}
8585

8686
private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)
@@ -817,7 +817,7 @@ private void CheckInputColumnTypes(Schema schema)
817817
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "vector of two or more items of type float", scoreType.ToString());
818818
var labelType = schema[LabelIndex].Type;
819819
if (labelType != NumberType.Float && labelType.GetKeyCount() <= 0)
820-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "float or key", labelType.ToString());
820+
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "float or KeyType", labelType.ToString());
821821
}
822822
}
823823

src/Microsoft.ML.Data/Evaluators/MultiOutputRegressionEvaluator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
5959
var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
6060
var t = score.Type as VectorType;
6161
if (t == null || !t.IsKnownSize || t.ItemType != NumberType.Float)
62-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "known size vector of R4", t.ToString());
62+
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "known-size vector of float", t.ToString());
6363
Host.Check(schema.Label.HasValue, "Could not find the label column");
6464
t = schema.Label.Value.Type as VectorType;
6565
if (t == null || !t.IsKnownSize || (t.ItemType != NumberType.R4 && t.ItemType != NumberType.R8))
66-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "known size vector of R4 or R8", t.ToString());
66+
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "known-size vector of float or double", t.ToString());
6767
}
6868

6969
private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)

src/Microsoft.ML.Data/Evaluators/QuantileRegressionEvaluator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
5757
var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
5858
var t = score.Type as VectorType;
5959
if (t == null || t.Size == 0 || (t.ItemType != NumberType.R4 && t.ItemType != NumberType.R8))
60-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "vector of type R4 or R8", t.ToString());
60+
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "vector of float or double", t.ToString());
6161
Host.CheckParam(schema.Label.HasValue, nameof(schema), "Must contain a label column");
6262
var labelType = schema.Label.Value.Type;
6363
if (labelType != NumberType.R4)
64-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "R4", t.ToString());
64+
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float", t.ToString());
6565
}
6666

6767
private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)

src/Microsoft.ML.Data/Evaluators/RegressionEvaluator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
5656
var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
5757
var t = score.Type;
5858
if (t != NumberType.Float)
59-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "R4", t.ToString());
59+
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "float", t.ToString());
6060
Host.CheckParam(schema.Label.HasValue, nameof(schema), "Could not find the label column");
6161
t = schema.Label.Value.Type;
6262
if (t != NumberType.R4)
63-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "R4", t.ToString());
63+
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float", t.ToString());
6464
}
6565

6666
private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)

src/Microsoft.ML.Data/Scorers/PredictionTransformer.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public SingleFeaturePredictionTransformerBase(IHost host, TModel model, Schema t
176176
if (featureColumn == null)
177177
FeatureColumnType = null;
178178
else if (!trainSchema.TryGetColumnIndex(featureColumn, out int col))
179-
throw Host.ExceptSchemaMismatch(nameof(featureColumn), RoleMappedSchema.ColumnRole.Feature.Value, featureColumn);
179+
throw Host.ExceptSchemaMismatch(nameof(featureColumn), "feature", featureColumn);
180180
else
181181
FeatureColumnType = trainSchema[col].Type;
182182

@@ -191,7 +191,7 @@ internal SingleFeaturePredictionTransformerBase(IHost host, ModelLoadContext ctx
191191
if (FeatureColumn == null)
192192
FeatureColumnType = null;
193193
else if (!TrainSchema.TryGetColumnIndex(FeatureColumn, out int col))
194-
throw Host.ExceptSchemaMismatch(nameof(FeatureColumn), RoleMappedSchema.ColumnRole.Feature.Value, FeatureColumn);
194+
throw Host.ExceptSchemaMismatch(nameof(FeatureColumn), "feature", FeatureColumn);
195195
else
196196
FeatureColumnType = TrainSchema[col].Type;
197197

@@ -205,9 +205,9 @@ public override Schema GetOutputSchema(Schema inputSchema)
205205
if (FeatureColumn != null)
206206
{
207207
if (!inputSchema.TryGetColumnIndex(FeatureColumn, out int col))
208-
throw Host.ExceptSchemaMismatch(nameof(inputSchema), RoleMappedSchema.ColumnRole.Feature.Value, FeatureColumn, FeatureColumnType.ToString(), null);
208+
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "feature", FeatureColumn);
209209
if (!inputSchema[col].Type.Equals(FeatureColumnType))
210-
throw Host.ExceptSchemaMismatch(nameof(inputSchema), RoleMappedSchema.ColumnRole.Feature.Value, FeatureColumn, FeatureColumnType.ToString(), inputSchema[col].Type.ToString());
210+
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "feature", FeatureColumn, FeatureColumnType.ToString(), inputSchema[col].Type.ToString());
211211
}
212212

213213
return Transform(new EmptyDataView(Host, inputSchema)).Schema;

src/Microsoft.ML.Data/Transforms/FeatureContributionCalculationTransform.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public Mapper(FeatureContributionCalculatingTransformer parent, Schema schema)
224224
throw Host.ExceptSchemaMismatch(nameof(schema), "input", _parent.ColumnPairs[0].input);
225225
_featureColumnType = schema[_featureColumnIndex].Type as VectorType;
226226
if (_featureColumnType == null || _featureColumnType.ItemType != NumberType.R4)
227-
throw Host.ExceptSchemaMismatch(nameof(schema), "feature column", _parent.ColumnPairs[0].input, "Expected type is vector of float.", _featureColumnType.ItemType.ToString());
227+
throw Host.ExceptSchemaMismatch(nameof(schema), "feature", _parent.ColumnPairs[0].input, "vector of float.", _featureColumnType.ItemType.ToString());
228228

229229
if (InputSchema[_featureColumnIndex].HasSlotNames(_featureColumnType.Size))
230230
InputSchema[_featureColumnIndex].Metadata.GetValue(MetadataUtils.Kinds.SlotNames, ref _slotNames);
@@ -319,7 +319,7 @@ public override SchemaShape GetOutputSchema(SchemaShape inputSchema)
319319
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "input", _featureColumn);
320320
// Check that the feature column is of the correct type: a vector of float.
321321
if (col.ItemType != NumberType.R4 || col.Kind != SchemaShape.Column.VectorKind.Vector)
322-
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "feature column", _featureColumn, "Expected type is vector of float.", col.GetTypeString());
322+
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "column", _featureColumn, "vector of float.", col.GetTypeString());
323323

324324
// Build output schemaShape.
325325
var result = inputSchema.ToDictionary(x => x.Name);

src/Microsoft.ML.Data/Transforms/KeyToValue.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ public override SchemaShape GetOutputSchema(SchemaShape inputSchema)
521521
if (!inputSchema.TryFindColumn(colInfo.input, out var col))
522522
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "input", colInfo.input);
523523
if (!col.IsKey)
524-
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "input", colInfo.input, "key type", col.GetTypeString());
524+
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "input", colInfo.input, "KeyType", col.GetTypeString());
525525

526526
if (!col.Metadata.TryFindColumn(MetadataUtils.Kinds.KeyValues, out var keyMetaCol))
527527
throw Host.ExceptParam(nameof(inputSchema), $"Input column '{colInfo.input}' doesn't contain key values metadata");

src/Microsoft.ML.Data/Transforms/NAFilter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public NAFilter(IHost host, ModelLoadContext ctx, IDataView input)
150150

151151
var type = schema[index].Type;
152152
if (!TestType(type))
153-
throw Host.ExceptSchemaMismatch(nameof(schema), "source", src, "scalar or vector of float, double or key", type.ToString());
153+
throw Host.ExceptSchemaMismatch(nameof(schema), "source", src, "scalar or vector of float, double or KeyType", type.ToString());
154154

155155
_infos[i] = new ColInfo(index, type);
156156
_srcIndexToInfoIndex.Add(index, i);

src/Microsoft.ML.Data/Transforms/Normalizer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,10 @@ public SchemaShape GetOutputSchema(SchemaShape inputSchema)
253253
if (!inputSchema.TryFindColumn(colInfo.Input, out var col))
254254
throw _host.ExceptSchemaMismatch(nameof(inputSchema), "input", colInfo.Input);
255255
if (col.Kind == SchemaShape.Column.VectorKind.VariableVector)
256-
throw _host.ExceptSchemaMismatch(nameof(inputSchema), "input", colInfo.Input, "fixed-size vector or scalar", col.GetTypeString());
256+
throw _host.ExceptSchemaMismatch(nameof(inputSchema), "input", colInfo.Input, "known-size vector or scalar", col.GetTypeString());
257257

258258
if (!col.ItemType.Equals(NumberType.R4) && !col.ItemType.Equals(NumberType.R8))
259-
throw _host.ExceptSchemaMismatch(nameof(inputSchema), "input", colInfo.Input, "vector or scalar of R4 or R8", col.GetTypeString());
259+
throw _host.ExceptSchemaMismatch(nameof(inputSchema), "input", colInfo.Input, "vector or scalar of float or double", col.GetTypeString());
260260

261261
var isNormalizedMeta = new SchemaShape.Column(MetadataUtils.Kinds.IsNormalized, SchemaShape.Column.VectorKind.Scalar,
262262
BoolType.Instance, false);

src/Microsoft.ML.Data/Transforms/RangeFilter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private RangeFilter(IHost host, ModelLoadContext ctx, IDataView input)
154154

155155
_type = schema[_index].Type;
156156
if (_type != NumberType.R4 && _type != NumberType.R8 && _type.GetKeyCount() == 0)
157-
throw Host.ExceptSchemaMismatch(nameof(schema), "source", column, "flaot, double or key", _type.ToString());
157+
throw Host.ExceptSchemaMismatch(nameof(schema), "source", column, "flaot, double or KeyType", _type.ToString());
158158

159159
_min = ctx.Reader.ReadDouble();
160160
_max = ctx.Reader.ReadDouble();

src/Microsoft.ML.EntryPoints/FeatureCombiner.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public static CommonOutputs.TransformOutput PrepareClassificationLabel(IHostEnvi
233233

234234
var labelCol = input.Data.Schema.GetColumnOrNull(input.LabelColumn);
235235
if (!labelCol.HasValue)
236-
throw host.ExceptSchemaMismatch(nameof(input), "Label", input.LabelColumn);
236+
throw host.ExceptSchemaMismatch(nameof(input), "label", input.LabelColumn);
237237

238238
var labelType = labelCol.Value.Type;
239239
if (labelType is KeyType || labelType is BoolType)
@@ -269,7 +269,7 @@ public static CommonOutputs.TransformOutput ConvertPredictedLabel(IHostEnvironme
269269

270270
var predictedLabelCol = input.Data.Schema.GetColumnOrNull(input.PredictedLabelColumn);
271271
if (!predictedLabelCol.HasValue)
272-
throw host.ExceptSchemaMismatch(nameof(input), "PredictedLabel",input.PredictedLabelColumn);
272+
throw host.ExceptSchemaMismatch(nameof(input), "label", input.PredictedLabelColumn);
273273
var predictedLabelType = predictedLabelCol.Value.Type;
274274
if (predictedLabelType is NumberType || predictedLabelType is BoolType)
275275
{

src/Microsoft.ML.FastTree/FastTreeRanking.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected override void CheckLabelCompatible(SchemaShape.Column labelCol)
100100
Contracts.Assert(labelCol.IsValid);
101101

102102
Action error =
103-
() => throw Host.ExceptSchemaMismatch(nameof(labelCol), RoleMappedSchema.ColumnRole.Label.Value, labelCol.Name, "R4 or a Key", labelCol.GetTypeString());
103+
() => throw Host.ExceptSchemaMismatch(nameof(labelCol), "label", labelCol.Name, "float or KeyType", labelCol.GetTypeString());
104104

105105
if (labelCol.Kind != SchemaShape.Column.VectorKind.Scalar)
106106
error();

src/Microsoft.ML.FastTree/TreeEnsembleFeaturizer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ private static IDataView AppendLabelTransform(IHostEnvironment env, IChannel ch,
719719

720720
var col = input.Schema.GetColumnOrNull(labelName);
721721
if (!col.HasValue)
722-
throw ch.ExceptSchemaMismatch(nameof(input), "Label", labelName);
722+
throw ch.ExceptSchemaMismatch(nameof(input), "label", labelName);
723723

724724
ColumnType labelType = col.Value.Type;
725725
if (!(labelType is KeyType))

src/Microsoft.ML.LightGBM/LightGbmRankingTrainer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protected override void CheckLabelCompatible(SchemaShape.Column labelCol)
145145
Contracts.Assert(labelCol.IsValid);
146146

147147
Action error =
148-
() => throw Host.ExceptSchemaMismatch(nameof(labelCol), RoleMappedSchema.ColumnRole.Label.Value, labelCol.Name, "R4 or a Key", labelCol.GetTypeString());
148+
() => throw Host.ExceptSchemaMismatch(nameof(labelCol), "label", labelCol.Name, "float or KeyType", labelCol.GetTypeString());
149149

150150
if (labelCol.Kind != SchemaShape.Column.VectorKind.Scalar)
151151
error();

src/Microsoft.ML.OnnxTransform/OnnxTransform.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ public override SchemaShape GetOutputSchema(SchemaShape inputSchema)
558558
if (!inputSchema.TryFindColumn(input, out var col))
559559
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "input", input);
560560
if (!(col.Kind == SchemaShape.Column.VectorKind.VariableVector || col.Kind == SchemaShape.Column.VectorKind.Vector))
561-
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "input", input, nameof(VectorType), col.GetTypeString());
561+
throw Host.ExceptSchemaMismatch(nameof(inputSchema), "input", input, "vector", col.GetTypeString());
562562

563563
var inputsInfo = Transformer.Model.ModelInfo.InputsInfo;
564564
var idx = Transformer.Model.InputNames.IndexOf(input);

src/Microsoft.ML.PCA/PcaTransform.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ internal static void ValidatePcaInput(IExceptionContext ectx, string name, Colum
549549
string inputSchema; // just used for the excpections
550550

551551
if (!(type is VectorType vectorType && vectorType.Size > 1 && vectorType.ItemType.Equals(NumberType.R4)))
552-
throw ectx.ExceptSchemaMismatch(nameof(inputSchema), "input", name, "vector of floats with fixed size greater than 1", type.ToString());
552+
throw ectx.ExceptSchemaMismatch(nameof(inputSchema), "input", name, "known-size vector of float of two or more items", type.ToString());
553553
}
554554

555555
private sealed class Mapper : OneToOneMapperBase

0 commit comments

Comments
 (0)