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

Add support for string vectors to DataFrame #6628

Merged
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: 4 additions & 0 deletions src/Microsoft.Data.Analysis/IDataView.Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ private static DataFrameColumn GetVectorDataFrame(VectorDataViewType vectorType,
{
return new VBufferDataFrameColumn<decimal>(name);
}
else if (itemType.RawType == typeof(ReadOnlyMemory<char>))
{
return new VBufferDataFrameColumn<ReadOnlyMemory<char>>(name);
}

throw new NotSupportedException(String.Format(Microsoft.Data.Strings.VectorSubTypeNotSupported, itemType.ToString()));
}
Expand Down
4 changes: 4 additions & 0 deletions src/Microsoft.Data.Analysis/VBufferDataFrameColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ private static VectorDataViewType GetDataViewType()
{
return new VectorDataViewType(NumberDataViewType.Double);
}
else if (typeof(T) == typeof(ReadOnlyMemory<char>))
{
return new VectorDataViewType(TextDataViewType.Instance);
}

throw new NotSupportedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ public void TestDataFrameFromIDataView_VBufferType()
ushortFeatures = new ushort[] {0, 0},
uintFeatures = new uint[] {0, 0},
ulongFeatures = new ulong[] {0, 0},
stringFeatures = new string[]{ "A", "B"},
},
new {
boolFeature = new bool[] {false, false},
Expand All @@ -474,13 +475,14 @@ public void TestDataFrameFromIDataView_VBufferType()
ushortFeatures = new ushort[] {0, 0},
uintFeatures = new uint[] {0, 0},
ulongFeatures = new ulong[] {0, 0},
stringFeatures = new string[]{ "A", "B"},
}
};

var data = mlContext.Data.LoadFromEnumerable(inputData);
var df = data.ToDataFrame();

Assert.Equal(11, df.Columns.Count);
Assert.Equal(12, df.Columns.Count);
Assert.Equal(2, df.Rows.Count);
}
}
Expand Down