Skip to content

Easier to create DataFrame from DataViewSchema #6473

Description

@FranklinWhale

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-DataFrameMicrosoft.Data.Analysis DataFrame APIsenhancementNew feature or requestyellowmaintenance only

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions