Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix accessing null object #5804

Merged
merged 1 commit into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Microsoft.Data.Analysis/DataFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public DataFrame Append(IEnumerable<object> row = null, bool inPlace = false)
value = Convert.ChangeType(value, column.DataType);
if (value is null)
{
throw new ArgumentException(string.Format(Strings.MismatchedValueType, column.DataType), value.GetType().ToString());
throw new ArgumentException(string.Format(Strings.MismatchedValueType, column.DataType), column.Name);
}
}
cachedObjectConversions.Add(value);
Expand Down Expand Up @@ -583,7 +583,7 @@ public DataFrame Append(IEnumerable<KeyValuePair<string, object>> row, bool inPl
value = Convert.ChangeType(value, column.DataType);
if (value is null)
{
throw new ArgumentException(string.Format(Strings.MismatchedValueType, column.DataType), value.GetType().ToString());
throw new ArgumentException(string.Format(Strings.MismatchedValueType, column.DataType), column.Name);
}
}
cachedObjectConversions.Add(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
var score = schema.GetUniqueColumn(AnnotationUtils.Const.ScoreValueKind.Score);
var t = score.Type as VectorDataViewType;
if (t == null || !t.IsKnownSize || t.ItemType != NumberDataViewType.Single)
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "known-size vector of Single", t.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "known-size vector of Single", score.Type.ToString());
Host.Check(schema.Label.HasValue, "Could not find the label column");
t = schema.Label.Value.Type as VectorDataViewType;
if (t == null || !t.IsKnownSize || (t.ItemType != NumberDataViewType.Single && t.ItemType != NumberDataViewType.Double))
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "known-size vector of Single or Double", t.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "label", schema.Label.Value.Name, "known-size vector of Single or Double", schema.Label.Value.Type.ToString());
}

private protected override Aggregator GetAggregatorCore(RoleMappedSchema schema, string stratName)
Expand Down Expand Up @@ -548,7 +548,7 @@ private void CheckInputColumnTypes(DataViewSchema schema, out VectorDataViewType

var t = schema[LabelIndex].Type as VectorDataViewType;
if (t == null || !t.IsKnownSize || (t.ItemType != NumberDataViewType.Single && t.ItemType != NumberDataViewType.Double))
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "known-size vector of Single or Double", t.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "known-size vector of Single or Double", schema[LabelIndex].Type.ToString());
labelType = new VectorDataViewType((PrimitiveDataViewType)t.ItemType, t.Size);
var slotNamesType = new VectorDataViewType(TextDataViewType.Instance, t.Size);
var builder = new DataViewSchema.Annotations.Builder();
Expand All @@ -557,7 +557,7 @@ private void CheckInputColumnTypes(DataViewSchema schema, out VectorDataViewType

t = schema[ScoreIndex].Type as VectorDataViewType;
if (t == null || !t.IsKnownSize || t.ItemType != NumberDataViewType.Single)
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "known-size vector of Single", t.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "known-size vector of Single", schema[ScoreIndex].Type.ToString());
scoreType = new VectorDataViewType((PrimitiveDataViewType)t.ItemType, t.Size);
builder = new DataViewSchema.Annotations.Builder();
builder.AddSlotNames(t.Size, CreateSlotNamesGetter(schema, ScoreIndex, scoreType.Size, "Predicted"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
var score = schema.GetUniqueColumn(AnnotationUtils.Const.ScoreValueKind.Score);
var scoreType = score.Type as VectorDataViewType;
if (scoreType == null || scoreType.Size < 2 || scoreType.ItemType != NumberDataViewType.Single)
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "vector of two or more items of type Single", scoreType.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "vector of two or more items of type Single", score.Type.ToString());
Host.CheckParam(schema.Label.HasValue, nameof(schema), "Could not find the label column");
var labelType = schema.Label.Value.Type;
if (labelType != NumberDataViewType.Single && labelType.GetKeyCount() <= 0)
Expand Down Expand Up @@ -859,7 +859,7 @@ private void CheckInputColumnTypes(DataViewSchema schema)

var scoreType = schema[ScoreIndex].Type as VectorDataViewType;
if (scoreType == null || scoreType.Size < 2 || scoreType.ItemType != NumberDataViewType.Single)
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "Vector of two or more items of type Single", scoreType.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "score", ScoreCol, "Vector of two or more items of type Single", schema[ScoreIndex].Type.ToString());
var labelType = schema[LabelIndex].Type;
if (labelType != NumberDataViewType.Single && labelType.GetKeyCount() <= 0)
throw Host.ExceptSchemaMismatch(nameof(schema), "label", LabelCol, "Single or Key", labelType.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private protected override void CheckScoreAndLabelTypes(RoleMappedSchema schema)
var score = schema.GetUniqueColumn(AnnotationUtils.Const.ScoreValueKind.Score);
var t = score.Type as VectorDataViewType;
if (t == null || t.Size == 0 || (t.ItemType != NumberDataViewType.Single && t.ItemType != NumberDataViewType.Double))
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "Vector of Single or Double", t.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "score", score.Name, "Vector of Single or Double", score.Type.ToString());
Host.CheckParam(schema.Label.HasValue, nameof(schema), "Must contain a label column");
var labelType = schema.Label.Value.Type;
if (labelType != NumberDataViewType.Single)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Mapper(FeatureContributionCalculatingTransformer parent, DataViewSchema s
throw Host.ExceptSchemaMismatch(nameof(schema), "input", _parent.ColumnPairs[0].inputColumnName);
_featureColumnType = schema[_featureColumnIndex].Type as VectorDataViewType;
if (_featureColumnType == null || _featureColumnType.ItemType != NumberDataViewType.Single)
throw Host.ExceptSchemaMismatch(nameof(schema), "feature", _parent.ColumnPairs[0].inputColumnName, "vector of Single", _featureColumnType.ItemType.ToString());
throw Host.ExceptSchemaMismatch(nameof(schema), "feature", _parent.ColumnPairs[0].inputColumnName, "vector of Single", schema[_featureColumnIndex].Type.ToString());

if (InputSchema[_featureColumnIndex].HasSlotNames(_featureColumnType.Size))
InputSchema[_featureColumnIndex].Annotations.GetValue(AnnotationUtils.Kinds.SlotNames, ref _slotNames);
Expand Down