Skip to content

Commit 8f031eb

Browse files
committed
review comments
1 parent a1ae83a commit 8f031eb

File tree

77 files changed

+261
-222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+261
-222
lines changed

src/Microsoft.ML.Core/Utilities/Contracts.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ public static Exception ExceptSchemaMismatch(this IExceptionContext ctx, string
469469
private static string MakeSchemaMismatchMsg(string columnRole, string columnName, string expectedType = null, string actualType = null)
470470
{
471471
if (actualType == null)
472-
return $"Could not find {columnRole} column '{columnName}'";
473-
return $"Schema mismatch for {columnRole} column '{columnName}': expected {expectedType}, got {actualType}";
472+
return $"Could not find {columnRole.ToLower()} column '{columnName}'";
473+
return $"Schema mismatch for {columnRole.ToLower()} column '{columnName}': expected {expectedType}, got {actualType}";
474474
}
475475

476476
// Check - these check a condition and if it fails, throw the corresponding exception.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public IDataView Cache(IDataView input, params string[] columnsToPrefetch)
4242
for (int i = 0; i < prefetch.Length; i++)
4343
{
4444
if (!input.Schema.TryGetColumnIndex(columnsToPrefetch[i], out prefetch[i]))
45-
throw Environment.ExceptSchemaMismatch(nameof(columnsToPrefetch), "prefetch", columnsToPrefetch[i]);
45+
throw Environment.ExceptSchemaMismatch(nameof(columnsToPrefetch), "Prefetch", columnsToPrefetch[i]);
4646
}
4747
return new CacheDataView(Environment, input, prefetch);
4848
}
@@ -87,7 +87,7 @@ public IDataView FilterByKeyColumnFraction(IDataView input, string columnName, d
8787

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

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,12 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
9696
var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
9797
var t = score.Type;
9898
if (t != NumberType.Float)
99-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "float", t.ToString());
99+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Score, score.Name, typeof(float), t.ToString());
100100
Host.Check(schema.Label.HasValue, "Could not find the label column");
101101
t = schema.Label.Value.Type;
102102
if (t != NumberType.Float && t.GetKeyCount() != 2)
103-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float or a KeyType with cardinality 2", t.ToString());
103+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Label, schema.Label.Value.Name,
104+
typeof(float).ToString() + " or a " + typeof(KeyType).ToString() + " with cardinality 2", t.ToString());
104105
}
105106

106107
private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)
@@ -631,13 +632,13 @@ private protected override void PrintFoldResultsCore(IChannel ch, Dictionary<str
631632
{
632633
int index;
633634
if (!top.Schema.TryGetColumnIndex(AnomalyDetectionEvaluator.TopKResultsColumns.Instance, out index))
634-
throw Host.ExceptSchemaMismatch(nameof(top.Schema), "instance", AnomalyDetectionEvaluator.TopKResultsColumns.Instance);
635+
throw Host.ExceptSchemaMismatch(nameof(top.Schema), "", AnomalyDetectionEvaluator.TopKResultsColumns.Instance);
635636
var instanceGetter = cursor.GetGetter<ReadOnlyMemory<char>>(index);
636637
if (!top.Schema.TryGetColumnIndex(AnomalyDetectionEvaluator.TopKResultsColumns.AnomalyScore, out index))
637-
throw Host.ExceptSchemaMismatch(nameof(top.Schema), "anomaly score", AnomalyDetectionEvaluator.TopKResultsColumns.AnomalyScore);
638+
throw Host.ExceptSchemaMismatch(nameof(top.Schema), "", AnomalyDetectionEvaluator.TopKResultsColumns.AnomalyScore);
638639
var scoreGetter = cursor.GetGetter<Single>(index);
639640
if (!top.Schema.TryGetColumnIndex(AnomalyDetectionEvaluator.TopKResultsColumns.Label, out index))
640-
throw Host.ExceptSchemaMismatch(nameof(top.Schema), "label", AnomalyDetectionEvaluator.TopKResultsColumns.Label);
641+
throw Host.ExceptSchemaMismatch(nameof(top.Schema), "", AnomalyDetectionEvaluator.TopKResultsColumns.Label);
641642
var labelGetter = cursor.GetGetter<Single>(index);
642643

643644
bool hasRows = false;
@@ -671,7 +672,7 @@ private protected override void PrintFoldResultsCore(IChannel ch, Dictionary<str
671672
// Find the number of anomalies, and the thresholds.
672673
int numAnomIndex;
673674
if (!overall.Schema.TryGetColumnIndex(AnomalyDetectionEvaluator.OverallMetrics.NumAnomalies, out numAnomIndex))
674-
throw Host.ExceptSchemaMismatch(nameof(overall.Schema), "number of anomalies", AnomalyDetectionEvaluator.OverallMetrics.NumAnomalies);
675+
throw Host.ExceptSchemaMismatch(nameof(overall.Schema), "", AnomalyDetectionEvaluator.OverallMetrics.NumAnomalies);
675676

676677
int stratCol;
677678
var hasStrat = overall.Schema.TryGetColumnIndex(MetricKinds.ColumnNames.StratCol, out stratCol);

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,12 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
129129
var host = Host.SchemaSensitive();
130130
var t = score.Type;
131131
if (t != NumberType.Float)
132-
throw host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "float", t.ToString());
132+
throw host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Score, score.Name, typeof(float), t.ToString());
133133
host.Check(schema.Label.HasValue, "Could not find the label column");
134134
t = schema.Label.Value.Type;
135135
if (t != NumberType.R4 && t != NumberType.R8 && t != BoolType.Instance && t.GetKeyCount() != 2)
136-
throw host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float, double, bool, or a KeyType with cardinality 2", t.ToString());
136+
throw host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Label, schema.Label.Value.Name,
137+
typeof(float).ToString() + ", " + typeof(double).ToString() + ", " + typeof(bool).ToString() + ", or a " + typeof(KeyType).ToString() + " with cardinality 2", t.ToString());
137138
}
138139

139140
private protected override void CheckCustomColumnTypesCore(RoleMappedSchema schema)
@@ -145,7 +146,7 @@ private protected override void CheckCustomColumnTypesCore(RoleMappedSchema sche
145146
host.CheckParam(prob.Count == 1, nameof(schema), "Cannot have multiple probability columns");
146147
var probType = prob[0].Type;
147148
if (probType != NumberType.Float)
148-
throw host.ExceptSchemaMismatch(nameof(schema), "probability", prob[0].Name, "float", probType.ToString());
149+
throw host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Probability, prob[0].Name, typeof(float), probType.ToString());
149150
}
150151
else if (!_useRaw)
151152
{
@@ -1098,18 +1099,19 @@ private void CheckInputColumnTypes(Schema schema)
10981099

10991100
var t = schema[(int)LabelIndex].Type;
11001101
if (t != NumberType.R4 && t != NumberType.R8 && t != BoolType.Instance && t.GetKeyCount() != 2)
1101-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "float, double, bool or a KeyType with cardinality 2", t.ToString());
1102+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Label, LabelCol,
1103+
typeof(float).ToString() + ", " + typeof(double).ToString() + ", " + typeof(bool).ToString() + ", or a " + typeof(KeyType).ToString() + " with cardinality 2", t.ToString());
11021104

11031105
t = schema[ScoreIndex].Type;
11041106
if (t != NumberType.Float)
1105-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "float", t.ToString());
1107+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Score, ScoreCol, typeof(float), t.ToString());
11061108

11071109
if (_probIndex >= 0)
11081110
{
11091111
Host.Assert(!string.IsNullOrEmpty(_probCol));
11101112
t = schema[_probIndex].Type;
11111113
if (t != NumberType.Float)
1112-
throw Host.ExceptSchemaMismatch(nameof(schema), "probability", _probCol, "float", t.ToString());
1114+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Probability, _probCol, typeof(float), t.ToString());
11131115
}
11141116
else if (!_useRaw)
11151117
throw Host.Except("Cannot compute the predicted label from the probability column because it does not exist");

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
9999
ColumnType type = schema.Label?.Type;
100100
if (type != null && type != NumberType.Float && !(type is KeyType keyType && keyType.Count > 0))
101101
{
102-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name,
103-
"float or KeyType", type.ToString());
102+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Label, schema.Label.Value.Name,
103+
new[] { typeof(float), typeof(KeyType) }, type.ToString());
104104
}
105105

106106
var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
107107
type = score.Type;
108108
if (!(type is VectorType vectorType) || !vectorType.IsKnownSize || vectorType.ItemType != NumberType.Float)
109-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "known-size vector of float", type.ToString());
109+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Score, score.Name, "known-size vector of " + typeof(float).ToString(), type.ToString());
110110
}
111111

112112
private protected override void CheckCustomColumnTypesCore(RoleMappedSchema schema)
@@ -117,8 +117,8 @@ private protected override void CheckCustomColumnTypesCore(RoleMappedSchema sche
117117
var t = schema.Feature.Value.Type;
118118
if (!(t is VectorType vectorType) || !vectorType.IsKnownSize || vectorType.ItemType != NumberType.Float)
119119
{
120-
throw Host.ExceptSchemaMismatch(nameof(schema), "features", schema.Feature.Value.Name,
121-
"R4 vector of known size", t.ToString());
120+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Features, schema.Feature.Value.Name,
121+
"known-size vector of " + typeof(float).ToString(), t.ToString());
122122
}
123123
}
124124
}
@@ -754,7 +754,7 @@ private void CheckInputColumnTypes(Schema schema)
754754

755755
var type = schema[(int) ScoreIndex].Type;
756756
if (!(type is VectorType vectorType) || !vectorType.IsKnownSize || vectorType.ItemType != NumberType.Float)
757-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "known-size vector of float", type.ToString());
757+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Score, ScoreCol, "known-size vector of " + typeof(float).ToString(), type.ToString());
758758
}
759759
}
760760

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@ protected PerInstanceEvaluatorBase(IHostEnvironment env, Schema schema, string s
486486
LabelCol = labelCol;
487487

488488
if (!string.IsNullOrEmpty(LabelCol) && !schema.TryGetColumnIndex(LabelCol, out LabelIndex))
489-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol);
489+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Label, LabelCol);
490490
if (!schema.TryGetColumnIndex(ScoreCol, out ScoreIndex))
491-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol);
491+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Score, ScoreCol);
492492
}
493493

494494
protected PerInstanceEvaluatorBase(IHostEnvironment env, ModelLoadContext ctx, Schema schema)
@@ -502,9 +502,9 @@ protected PerInstanceEvaluatorBase(IHostEnvironment env, ModelLoadContext ctx,
502502
ScoreCol = ctx.LoadNonEmptyString();
503503
LabelCol = ctx.LoadStringOrNull();
504504
if (!string.IsNullOrEmpty(LabelCol) && !schema.TryGetColumnIndex(LabelCol, out LabelIndex))
505-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol);
505+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Label, LabelCol);
506506
if (!schema.TryGetColumnIndex(ScoreCol, out ScoreIndex))
507-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol);
507+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Score, ScoreCol);
508508
}
509509

510510
public virtual void Save(ModelSaveContext ctx)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
7777
var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
7878
var scoreType = score.Type as VectorType;
7979
if (scoreType == null || scoreType.Size < 2 || scoreType.ItemType != NumberType.Float)
80-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "vector of two or more items of type float", scoreType.ToString());
80+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Score, score.Name, "vector of two or more items of type " + typeof(float).ToString(), scoreType.ToString());
8181
Host.CheckParam(schema.Label.HasValue, nameof(schema), "Could not find the label column");
8282
var labelType = schema.Label.Value.Type;
8383
if (labelType != NumberType.Float && labelType.GetKeyCount() <= 0)
84-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "float or KeyType", labelType.ToString());
84+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Label, schema.Label.Value.Name, new[] { typeof(float), typeof(KeyType) }, labelType.ToString());
8585
}
8686

8787
private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)
@@ -815,10 +815,10 @@ private void CheckInputColumnTypes(Schema schema)
815815

816816
var scoreType = schema[ScoreIndex].Type as VectorType;
817817
if (scoreType == null || scoreType.Size < 2 || scoreType.ItemType != NumberType.Float)
818-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "vector of two or more items of type float", scoreType.ToString());
818+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Score, ScoreCol, "vector of two or more items of type " + typeof(float).ToString(), scoreType.ToString());
819819
var labelType = schema[LabelIndex].Type;
820820
if (labelType != NumberType.Float && labelType.GetKeyCount() <= 0)
821-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "float or KeyType", labelType.ToString());
821+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Label, LabelCol, new[] { typeof(float), typeof(KeyType) }, labelType.ToString());
822822
}
823823
}
824824

@@ -1000,7 +1000,7 @@ private protected override IDataView GetPerInstanceMetricsCore(IDataView perInst
10001000
// text file, since if there are different key counts the columns cannot be appended.
10011001
string labelName = schema.Label.Value.Name;
10021002
if (!perInst.Schema.TryGetColumnIndex(labelName, out int labelCol))
1003-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", labelName);
1003+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Label, labelName);
10041004
var labelType = perInst.Schema[labelCol].Type;
10051005
if (labelType is KeyType keyType && (!perInst.Schema[labelCol].HasKeyValues(keyType) || labelType.RawType != typeof(uint)))
10061006
{

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
6060
var score = schema.GetUniqueColumn(MetadataUtils.Const.ScoreValueKind.Score);
6161
var t = score.Type as VectorType;
6262
if (t == null || !t.IsKnownSize || t.ItemType != NumberType.Float)
63-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "known-size vector of float", t.ToString());
63+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Score, score.Name, "known-size vector of " + typeof(float).ToString(), t.ToString());
6464
Host.Check(schema.Label.HasValue, "Could not find the label column");
6565
t = schema.Label.Value.Type as VectorType;
6666
if (t == null || !t.IsKnownSize || (t.ItemType != NumberType.R4 && t.ItemType != NumberType.R8))
67-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "known-size vector of float or double", t.ToString());
67+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Label, schema.Label.Value.Name,
68+
"known-size vector of " + typeof(float).ToString() + " or " + typeof(double).ToString(), t.ToString());
6869
}
6970

7071
private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)
@@ -548,7 +549,8 @@ private void CheckInputColumnTypes(Schema schema, out VectorType labelType, out
548549

549550
var t = schema[LabelIndex].Type as VectorType;
550551
if (t == null || !t.IsKnownSize || (t.ItemType != NumberType.R4 && t.ItemType != NumberType.R8))
551-
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "known-size vector of float or double", t.ToString());
552+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Label, LabelCol,
553+
"known-size vector of " + typeof(float).ToString() + " or " + typeof(double).ToString(), t.ToString());
552554
labelType = new VectorType((PrimitiveType)t.ItemType, t.Size);
553555
var slotNamesType = new VectorType(TextType.Instance, t.Size);
554556
var builder = new MetadataBuilder();
@@ -557,7 +559,7 @@ private void CheckInputColumnTypes(Schema schema, out VectorType labelType, out
557559

558560
t = schema[ScoreIndex].Type as VectorType;
559561
if (t == null || !t.IsKnownSize || t.ItemType != NumberType.Float)
560-
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "known-size vector of float", t.ToString());
562+
throw Host.ExceptSchemaMismatch(nameof(schema), DefaultColumnNames.Score, ScoreCol, "known-size vector of " + typeof(float).ToString(), t.ToString());
561563
scoreType = new VectorType((PrimitiveType)t.ItemType, t.Size);
562564
builder = new MetadataBuilder();
563565
builder.AddSlotNames(t.Size, CreateSlotNamesGetter(schema, ScoreIndex, scoreType.Size, "Predicted"));

0 commit comments

Comments
 (0)