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

Move DataFrame to machinelearning #5641

Merged
merged 54 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
df1661b
Change namespace to Microsoft.Data.Analysis (#2773)
Nov 6, 2019
f09c30c
APIs for reversed binary operators (#2769)
Nov 7, 2019
afe3e61
Throw for incompatible inPlace (#2778)
Nov 8, 2019
5c4b1b4
Version, Tags and Description for Nuget (#2779)
Nov 8, 2019
5de343c
Flags for release (#2781)
Nov 9, 2019
81f3d42
Fix the Description method to not throw (#2786)
Nov 22, 2019
c6eb2f7
Use dataTypes if it passed in to LoadCsv (#2791)
Dec 3, 2019
7cee9d9
Creating a `Rows` property, similar to `Columns` (#2794)
Dec 5, 2019
e64cbad
DataFrame.LoadCsv throws an exception on projects targeting < netcore…
eerhardt Dec 5, 2019
303ba62
Params constructor on DataFrame (#2800)
Dec 6, 2019
dc4f9b0
Remove `T : unmanaged` constraint from DataFrameColumn.BinaryOperatio…
Dec 12, 2019
838350b
Bump version to 0.2.0 (#2803)
Dec 12, 2019
0fa210d
Add Apply<TResult>method to PrimitiveDataFrameColumn (#2807)
zHaytam Jan 13, 2020
430ac09
Add additional tests for ReadCsv (#2811)
jwood803 Jan 16, 2020
70bb9e9
Added static factory methods to DataFrameColumn (#2808)
MgSam Jan 21, 2020
82c315f
Append rows to a DataFrame (#2823)
Jan 28, 2020
afdbc5b
Move corefxlab to arcade (#2795)
Feb 7, 2020
355d3fb
Rename Sort to OrderBy (#2814)
jwood803 Feb 20, 2020
9e10004
Explode column types and generate converters (#2857)
Mar 4, 2020
1544c23
Address remaining concerns from the 2nd DataFrame API Review (#2861)
Mar 9, 2020
8d7fb66
Add binary operations and operators on the exploded columns (#2867)
Mar 19, 2020
7ef10ba
Add APIs to get the strongly typed columns from a DataFrame (#2878)
Mar 20, 2020
4072f96
Enable xml docs for Data.Analysis (#2882)
Mar 21, 2020
a6c34d0
Add Apply to ArrowStringDataFrameColumn (#2889)
Mar 23, 2020
9c80608
Support for Exploded columns types in Arrow and IO scenarios (#2885)
Mar 23, 2020
d120982
Bump version (#2890)
Mar 24, 2020
59df417
Fix versioning to allow for individual stable packages (#2891)
Mar 24, 2020
d79dd2f
Bump Microsoft.Data.Analysis version to 0.4.0 (#2892)
eerhardt Mar 25, 2020
28140bd
Fix https://github.com/dotnet/corefxlab/issues/2906 (#2907)
Apr 30, 2020
5c3ac8b
Improve LoadCsv to handle null values when deducing the column types …
May 19, 2020
0bef531
Create a 0.4.0 package (#2918)
May 20, 2020
b215eb4
Revert "Create a 0.4.0 package (#2918)" (#2919)
May 20, 2020
3b4aafa
Produce a 0.4.0 build (#2920)
May 20, 2020
8d08434
Default Length for StringDataFrameColumn (#2921) (#2923)
rhysparry May 25, 2020
7dcf184
Increment version and stop producing stable packages (#2922)
May 26, 2020
881886b
Add DataFrame object formatter. (#2931)
dcostea Jun 11, 2020
6e60307
Fix a bug in InsertColumn
RamonWill Jun 24, 2020
6c2d800
Add Microsoft.Data.Analysis.nuget project (#2933)
dcostea Jul 27, 2020
7ebe8bc
ColumnName indexer on DataFrame (#2959)
Sep 2, 2020
54633a2
Implement FillNulls() for ArrowStringDataFrameColumn with inPlace: fa…
RamonWill Sep 2, 2020
4e6d801
Prevent DataFrame.Sample() method from returning duplicated rows (#2939)
RamonWill Sep 10, 2020
81d0ba5
Add WriteCsv plus unit tests. (#2947)
dcostea Oct 1, 2020
db5c49e
Missing values default to a `StringDataFrameColumn` (#2982)
Oct 20, 2020
cb7ab00
Update FromArrowRecordBatches for dotnet-spark (#2978)
Oct 23, 2020
cff30e3
Implement DataFrame.LoadCsvFromString (#2988)
Oct 30, 2020
e7a9c42
Part 1 of porting the csv reader (#2997)
Dec 3, 2020
881c619
Merge branch 'port' of ../corefxlab into DataFrame_1
Mar 3, 2021
1c1c3a8
Move to the test folder
Mar 3, 2021
fea6bd2
Suppress warnings
Mar 3, 2021
0b8541a
Move extensions reference out of props
Mar 3, 2021
bf82179
Address feedback
Mar 5, 2021
9d74a83
Address feedback
Mar 8, 2021
fa39b74
Default to preview version
Mar 8, 2021
216554a
Update nuget.config
Mar 10, 2021
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
108 changes: 108 additions & 0 deletions Microsoft.ML.sln
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML", "src\Microso
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.ML.Mkl.Redist", "src\Microsoft.ML.Mkl.Redist\Microsoft.ML.Mkl.Redist.csproj", "{4584326B-C5B3-4CAE-B98A-34C5F5AA16F3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.Analysis", "src\Microsoft.Data.Analysis\Microsoft.Data.Analysis.csproj", "{84150C22-0627-4A11-81C9-F214762855EA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.Analysis.Interactive", "src\Microsoft.Data.Analysis.Interactive\Microsoft.Data.Analysis.Interactive.csproj", "{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.Analysis.Tests", "test\Microsoft.Data.Analysis.Tests\Microsoft.Data.Analysis.Tests.csproj", "{0B765344-11A4-4738-9759-5060599DC134}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Data.Analysis.Interactive.Tests", "test\Microsoft.Data.Analysis.Interactive.Tests\Microsoft.Data.Analysis.Interactive.Tests.csproj", "{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1680,6 +1688,102 @@ Global
{4584326B-C5B3-4CAE-B98A-34C5F5AA16F3}.Release-netfx|Any CPU.Build.0 = Release-netfx|Any CPU
{4584326B-C5B3-4CAE-B98A-34C5F5AA16F3}.Release-netfx|x64.ActiveCfg = Release-netfx|Any CPU
{4584326B-C5B3-4CAE-B98A-34C5F5AA16F3}.Release-netfx|x64.Build.0 = Release-netfx|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Debug|x64.ActiveCfg = Debug|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Debug|x64.Build.0 = Debug|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Debug-netcoreapp3_1|Any CPU.ActiveCfg = Debug-netcoreapp3_1|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Debug-netcoreapp3_1|Any CPU.Build.0 = Debug-netcoreapp3_1|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Debug-netcoreapp3_1|x64.ActiveCfg = Debug-netcoreapp3_1|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Debug-netcoreapp3_1|x64.Build.0 = Debug-netcoreapp3_1|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Debug-netfx|Any CPU.ActiveCfg = Debug-netfx|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Debug-netfx|Any CPU.Build.0 = Debug-netfx|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Debug-netfx|x64.ActiveCfg = Debug-netfx|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Debug-netfx|x64.Build.0 = Debug-netfx|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Release|Any CPU.Build.0 = Release|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Release|x64.ActiveCfg = Release|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Release|x64.Build.0 = Release|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Release-netcoreapp3_1|Any CPU.ActiveCfg = Release-netcoreapp3_1|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Release-netcoreapp3_1|Any CPU.Build.0 = Release-netcoreapp3_1|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Release-netcoreapp3_1|x64.ActiveCfg = Release-netcoreapp3_1|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Release-netcoreapp3_1|x64.Build.0 = Release-netcoreapp3_1|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Release-netfx|Any CPU.ActiveCfg = Release-netfx|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Release-netfx|Any CPU.Build.0 = Release-netfx|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Release-netfx|x64.ActiveCfg = Release-netfx|Any CPU
{84150C22-0627-4A11-81C9-F214762855EA}.Release-netfx|x64.Build.0 = Release-netfx|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Debug|x64.ActiveCfg = Debug|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Debug|x64.Build.0 = Debug|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Debug-netcoreapp3_1|Any CPU.ActiveCfg = Debug-netcoreapp3_1|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Debug-netcoreapp3_1|Any CPU.Build.0 = Debug-netcoreapp3_1|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Debug-netcoreapp3_1|x64.ActiveCfg = Debug-netcoreapp3_1|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Debug-netcoreapp3_1|x64.Build.0 = Debug-netcoreapp3_1|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Debug-netfx|Any CPU.ActiveCfg = Debug-netfx|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Debug-netfx|Any CPU.Build.0 = Debug-netfx|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Debug-netfx|x64.ActiveCfg = Debug-netfx|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Debug-netfx|x64.Build.0 = Debug-netfx|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Release|Any CPU.Build.0 = Release|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Release|x64.ActiveCfg = Release|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Release|x64.Build.0 = Release|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Release-netcoreapp3_1|Any CPU.ActiveCfg = Release-netcoreapp3_1|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Release-netcoreapp3_1|Any CPU.Build.0 = Release-netcoreapp3_1|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Release-netcoreapp3_1|x64.ActiveCfg = Release-netcoreapp3_1|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Release-netcoreapp3_1|x64.Build.0 = Release-netcoreapp3_1|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Release-netfx|Any CPU.ActiveCfg = Release-netfx|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Release-netfx|Any CPU.Build.0 = Release-netfx|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Release-netfx|x64.ActiveCfg = Release-netfx|Any CPU
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923}.Release-netfx|x64.Build.0 = Release-netfx|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Debug|x64.ActiveCfg = Debug|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Debug|x64.Build.0 = Debug|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Debug-netcoreapp3_1|Any CPU.ActiveCfg = Debug-netcoreapp3_1|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Debug-netcoreapp3_1|Any CPU.Build.0 = Debug-netcoreapp3_1|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Debug-netcoreapp3_1|x64.ActiveCfg = Debug-netcoreapp3_1|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Debug-netcoreapp3_1|x64.Build.0 = Debug-netcoreapp3_1|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Debug-netfx|Any CPU.ActiveCfg = Debug-netfx|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Debug-netfx|Any CPU.Build.0 = Debug-netfx|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Debug-netfx|x64.ActiveCfg = Debug-netfx|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Debug-netfx|x64.Build.0 = Debug-netfx|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Release|Any CPU.Build.0 = Release|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Release|x64.ActiveCfg = Release|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Release|x64.Build.0 = Release|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Release-netcoreapp3_1|Any CPU.ActiveCfg = Release-netcoreapp3_1|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Release-netcoreapp3_1|Any CPU.Build.0 = Release-netcoreapp3_1|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Release-netcoreapp3_1|x64.ActiveCfg = Release-netcoreapp3_1|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Release-netcoreapp3_1|x64.Build.0 = Release-netcoreapp3_1|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Release-netfx|Any CPU.ActiveCfg = Release-netfx|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Release-netfx|Any CPU.Build.0 = Release-netfx|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Release-netfx|x64.ActiveCfg = Release-netfx|Any CPU
{0B765344-11A4-4738-9759-5060599DC134}.Release-netfx|x64.Build.0 = Release-netfx|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Debug|x64.ActiveCfg = Debug|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Debug|x64.Build.0 = Debug|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Debug-netcoreapp3_1|Any CPU.ActiveCfg = Debug-netcoreapp3_1|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Debug-netcoreapp3_1|Any CPU.Build.0 = Debug-netcoreapp3_1|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Debug-netcoreapp3_1|x64.ActiveCfg = Debug-netcoreapp3_1|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Debug-netcoreapp3_1|x64.Build.0 = Debug-netcoreapp3_1|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Debug-netfx|Any CPU.ActiveCfg = Debug-netfx|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Debug-netfx|Any CPU.Build.0 = Debug-netfx|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Debug-netfx|x64.ActiveCfg = Debug-netfx|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Debug-netfx|x64.Build.0 = Debug-netfx|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Release|Any CPU.Build.0 = Release|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Release|x64.ActiveCfg = Release|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Release|x64.Build.0 = Release|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Release-netcoreapp3_1|Any CPU.ActiveCfg = Release-netcoreapp3_1|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Release-netcoreapp3_1|Any CPU.Build.0 = Release-netcoreapp3_1|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Release-netcoreapp3_1|x64.ActiveCfg = Release-netcoreapp3_1|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Release-netcoreapp3_1|x64.Build.0 = Release-netcoreapp3_1|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Release-netfx|Any CPU.ActiveCfg = Release-netfx|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Release-netfx|Any CPU.Build.0 = Release-netfx|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Release-netfx|x64.ActiveCfg = Release-netfx|Any CPU
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25}.Release-netfx|x64.Build.0 = Release-netfx|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1749,6 +1853,10 @@ Global
{C8DB58DC-6434-4431-A81F-263D86E2A5F3} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
{6CF88209-69DB-4B36-9604-3ECD9F163E96} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{4584326B-C5B3-4CAE-B98A-34C5F5AA16F3} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{84150C22-0627-4A11-81C9-F214762855EA} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{D9FDD2D5-BFFC-4A4D-8589-7F63AA3EA923} = {09EADF06-BE25-4228-AB53-95AE3E15B530}
{0B765344-11A4-4738-9759-5060599DC134} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
{8AFB8CC3-DA0B-4364-BFB3-296A7C54CC25} = {AED9C836-31E3-4F3F-8ABC-929555D3F3C4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {41165AF1-35BB-4832-A189-73060F82B01D}
Expand Down
155 changes: 155 additions & 0 deletions src/Microsoft.Data.Analysis.Interactive/DataFrameKernelExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.DotNet.Interactive;
using Microsoft.DotNet.Interactive.Formatting;
using static Microsoft.DotNet.Interactive.Formatting.PocketViewTags;

namespace Microsoft.Data.Analysis.Interactive
{
public class DataFrameKernelExtension : IKernelExtension
{
public Task OnLoadAsync(Kernel kernel)
{
RegisterDataFrame();

return Task.CompletedTask;
}

public static void RegisterDataFrame()
{
Formatter<DataFrame>.Register((df, writer) =>
{
const int MAX = 10000;
const int SIZE = 10;

var uniqueId = DateTime.Now.Ticks;

var header = new List<IHtmlContent>
{
th(i("index"))
};
header.AddRange(df.Columns.Select(c => (IHtmlContent)th(c.Name)));

if (df.Rows.Count > SIZE)
{
var maxMessage = df.Rows.Count > MAX ? $" (showing a max of {MAX} rows)" : string.Empty;
var title = h3[style: "text-align: center;"]($"DataFrame - {df.Rows.Count} rows {maxMessage}");

// table body
var maxRows = Math.Min(MAX, df.Rows.Count);
var rows = new List<List<IHtmlContent>>();
for (var index = 0; index < maxRows; index++)
{
var cells = new List<IHtmlContent>
{
td(i((index)))
};
foreach (var obj in df.Rows[index])
{
cells.Add(td(obj));
}
rows.Add(cells);
}

//navigator
var footer = new List<IHtmlContent>();
BuildHideRowsScript(uniqueId);

var paginateScriptFirst = BuildHideRowsScript(uniqueId) + GotoPageIndex(uniqueId, 0) + BuildPageScript(uniqueId, SIZE);
footer.Add(button[style: "margin: 2px;", onclick: paginateScriptFirst]("⏮"));

var paginateScriptPrevTen = BuildHideRowsScript(uniqueId) + UpdatePageIndex(uniqueId, -10, (maxRows - 1) / SIZE) + BuildPageScript(uniqueId, SIZE);
footer.Add(button[style: "margin: 2px;", onclick: paginateScriptPrevTen]("⏪"));

var paginateScriptPrev = BuildHideRowsScript(uniqueId) + UpdatePageIndex(uniqueId, -1, (maxRows - 1) / SIZE) + BuildPageScript(uniqueId, SIZE);
footer.Add(button[style: "margin: 2px;", onclick: paginateScriptPrev]("◀️"));

footer.Add(b[style: "margin: 2px;"]("Page"));
footer.Add(b[id: $"page_{uniqueId}", style: "margin: 2px;"]("1"));

var paginateScriptNext = BuildHideRowsScript(uniqueId) + UpdatePageIndex(uniqueId, 1, (maxRows - 1) / SIZE) + BuildPageScript(uniqueId, SIZE);
footer.Add(button[style: "margin: 2px;", onclick: paginateScriptNext]("▶️"));

var paginateScriptNextTen = BuildHideRowsScript(uniqueId) + UpdatePageIndex(uniqueId, 10, (maxRows - 1) / SIZE) + BuildPageScript(uniqueId, SIZE);
footer.Add(button[style: "margin: 2px;", onclick: paginateScriptNextTen]("⏩"));

var paginateScriptLast = BuildHideRowsScript(uniqueId) + GotoPageIndex(uniqueId, (maxRows - 1) / SIZE) + BuildPageScript(uniqueId, SIZE);
footer.Add(button[style: "margin: 2px;", onclick: paginateScriptLast]("⏭️"));

//table
var t = table[id: $"table_{uniqueId}"](
caption(title),
thead(tr(header)),
tbody(rows.Select(r => tr[style: "display: none"](r))),
tfoot(tr(td[colspan: df.Columns.Count + 1, style: "text-align: center;"](footer)))
);
writer.Write(t);

//show first page
writer.Write($"<script>{BuildPageScript(uniqueId, SIZE)}</script>");
}
else
{
var rows = new List<List<IHtmlContent>>();
for (var index = 0; index < df.Rows.Count; index++)
{
var cells = new List<IHtmlContent>
{
td(i((index)))
};
foreach (var obj in df.Rows[index])
{
cells.Add(td(obj));
}
rows.Add(cells);
}

//table
var t = table[id: $"table_{uniqueId}"](
thead(tr(header)),
tbody(rows.Select(r => tr(r)))
);
writer.Write(t);
}
}, "text/html");
}

private static string BuildHideRowsScript(long uniqueId)
{
var script = $"var allRows = document.querySelectorAll('#table_{uniqueId} tbody tr:nth-child(n)'); ";
script += "for (let i = 0; i < allRows.length; i++) { allRows[i].style.display='none'; } ";
return script;
}

private static string BuildPageScript(long uniqueId, int size)
{
var script = $"var page = parseInt(document.querySelector('#page_{uniqueId}').innerHTML) - 1; ";
script += $"var pageRows = document.querySelectorAll(`#table_{uniqueId} tbody tr:nth-child(n + ${{page * {size} + 1 }})`); ";
script += $"for (let j = 0; j < {size}; j++) {{ pageRows[j].style.display='table-row'; }} ";
return script;
}

private static string GotoPageIndex(long uniqueId, long page)
{
var script = $"document.querySelector('#page_{uniqueId}').innerHTML = {page + 1}; ";
return script;
}

private static string UpdatePageIndex(long uniqueId, int step, long maxPage)
{
var script = $"var page = parseInt(document.querySelector('#page_{uniqueId}').innerHTML) - 1; ";
script += $"page = parseInt(page) + parseInt({step}); ";
script += $"page = page < 0 ? 0 : page; ";
script += $"page = page > {maxPage} ? {maxPage} : page; ";
script += $"document.querySelector('#page_{uniqueId}').innerHTML = page + 1; ";
return script;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tabs hurt my eyes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, this setting must be mis-matched locally on my machine between VSCode and VS :\ Will fix in a bit

Copy link
Contributor Author

@pgovind pgovind Mar 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, how did you see tabs in this file in GH? I changed all tabs to spaces (no idea how tabs occurred in the first place) in 4 csprojs in the PR, but unfortunately there is no "Change all tabs to spaces in all files" in VS I think. For now, a solution wide regex search yields no tabs in source code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looked too indented then I saw it while trying to select white space.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use CodeFlow to review PRs, and you can tell it to show whitespace. Arrows are tabs, dots are spaces.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has codeflow been fixed to work better with Github comment threads? That was a deal breaker in the past.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it still has some issues with comment threads. Typically I only create new conversations from CodeFlow. And respond to threads in GH. I usually have them both open on 2 different windows. I just like seeing the full file, searching across the change, seeing the tree view of files, etc in CodeFlow. It's a much better experience for me.

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<NoWarn>$(NoWarn);MSML_ParameterLocalVarName;SA1028</NoWarn>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SA1028 is about code comments not formatting correctly. That seems like something we should be able to fix (either here or in a follow up PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. My plan is to do it in a follow up PR. SA1028 and a bunch of the other warnings are easily fixable

</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.0.0">
pgovind marked this conversation as resolved.
Show resolved Hide resolved
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
pgovind marked this conversation as resolved.
Show resolved Hide resolved
</PackageReference>
<PackageReference Include="Microsoft.DotNet.Interactive" Version="1.0.0-beta.20410.1" />
<PackageReference Include="Microsoft.DotNet.Interactive.Formatting" Version="1.0.0-beta.20410.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Data.Analysis\Microsoft.Data.Analysis.csproj" />
</ItemGroup>

</Project>
Loading