Is your feature request related to a problem? Please describe.
Loading a model returns a ITransformer and its input column information in a DataViewSchema. IDataView is required for making predictions and creating a DataFrame should be the simplest way, especially when it provides Append to add data row by row. Unfortunately, creating a DataFrame from a DataViewSchema is currently not easy because the DataFrame constructors basically only accepts IEnumerable<DataFrameColumn> and there is no direct conversion from DataViewSchema to IEnumerable<DataFrameColumn>.
Describe the solution you'd like
IDataViewExtensions.ToDataFrame actually contains the logic converting DataViewSchema to IEnumerable<DataFrameColumn>. To solve this issue, that part of the code will be moved to DataViewSchemaExtensions and DataViewTypeExtensions, 2 new extension classes that provide the following methods:
public static class DataViewSchemaExtensions
{
public static IEnumerable<DataFrameColumn> ToDataFrameColumns(this DataViewSchema schema, bool includesHidden = false, ISet<string>? selectColumns = null);
}
public static class DataViewTypeExtensions
{
public static DataFrameColumn CreateDataFrameColumn(this DataViewType type, string columnName);
}
Note that ToDataFrameColumns also provides an option to include hidden column in the resulting IEnumerable<DataFrameColumn>.
Describe alternatives you've considered
Another way to solve this issue is to create an IDataView from DataViewSchema then convert the IDataView to DataFrame using the existing extension method. Unfortunately, EmptyDataView is not public, and this involves some unnecessary operations.
Additional context
If the row data of the DataFrame are known, creating DataFrameColumn with the row data as values using Create likely has better performance than DataViewSchemaExtensions.ToDataFrameColumns followed by multiple Append calls. However, manual handling of DataViewType will be required.
Is your feature request related to a problem? Please describe.
Loading a model returns a
ITransformerand its input column information in aDataViewSchema.IDataViewis required for making predictions and creating aDataFrameshould be the simplest way, especially when it providesAppendto add data row by row. Unfortunately, creating aDataFramefrom aDataViewSchemais currently not easy because theDataFrameconstructors basically only acceptsIEnumerable<DataFrameColumn>and there is no direct conversion fromDataViewSchematoIEnumerable<DataFrameColumn>.Describe the solution you'd like
IDataViewExtensions.ToDataFrameactually contains the logic convertingDataViewSchematoIEnumerable<DataFrameColumn>. To solve this issue, that part of the code will be moved toDataViewSchemaExtensionsandDataViewTypeExtensions, 2 new extension classes that provide the following methods:Note that
ToDataFrameColumnsalso provides an option to include hidden column in the resultingIEnumerable<DataFrameColumn>.Describe alternatives you've considered
Another way to solve this issue is to create an
IDataViewfromDataViewSchemathen convert theIDataViewtoDataFrameusing the existing extension method. Unfortunately,EmptyDataViewis notpublic, and this involves some unnecessary operations.Additional context
If the row data of the
DataFrameare known, creatingDataFrameColumnwith the row data as values usingCreatelikely has better performance thanDataViewSchemaExtensions.ToDataFrameColumnsfollowed by multipleAppendcalls. However, manual handling ofDataViewTypewill be required.