Skip to content

User Story: Pandas-Inspired DataTable Extensions for RepoDB Notebook #1400

Open

Description

@mikependon

User Story

As a RepoDB Desktop Studio Notebook user, I want a rich, fluent set of System.Data.DataTable extension methods inspired by Python Pandas, so that I can inspect, clean, transform, combine, analyze, and prepare SQL query results for machine learning and data science directly in C#.

Background

RepoDB Desktop Studio Notebook supports SQL and runtime-compiled C# sections with shared results and variables. SQL sections can produce DataTable objects, and C# sections should be able to manipulate those tables without requiring Python or an external data-processing service.

Implement the functionality as a reusable .NET library (proposed name: RepoDb.DataFrame), independent of Avalonia and Studio. Start with extensions on DataTable; consider a lazy or columnar execution model later if performance requires it. The API should be Pandas-inspired, not a literal Pandas clone.

Proposed API Coverage

Category Methods Priority
Inspection Head, Tail, Sample, Shape, Info, Describe, DTypes, MemoryUsage, Unique, NUnique, ValueCounts P0
Selection and sorting SelectColumns, DropColumns, RenameColumns, Filter, Query, SortValues, SortIndex, TopN, BottomN P0
Missing data IsNull, NotNull, FillNulls, DropNulls P0
Transformation Assign, Apply, MapColumn, CastColumn, Replace, Clip, Round, Explode P0
Aggregation Sum, Mean, Median, Mode, Min, Max, Count, Std, Variance P0
Grouping GroupBy, Aggregate / Agg, Transform, Having P1
Combining Merge, Join, Concat, Union, Intersect, Except, CrossJoin P1
Reshaping Pivot, PivotTable, Melt, Stack, Unstack, Transpose P1
Statistics Corr, CorrMatrix, Cov, Quantile, Skew, Kurtosis, Cumsum, Cumprod, Rank, Histogram P1
ML preparation TrainTestSplit, Normalize, Standardize, MinMaxScale, OneHotEncode, LabelEncode, OrdinalEncode, ImputeMissing, SelectFeatures, DropFeatures, ToFeatureMatrix, ToLabelVector P1
Data quality Duplicated, DropDuplicates, Validate, Profile P1
Export and integration ToCsv, ToJson, ToParquet, ToMatrix, ToDataView P1
Time series Shift, Diff, PctChange, Rolling, RollingMean, Expanding, Ewm, Resample, BetweenTime, DatePart, Lag, Lead, Interpolate P2

Priority definitions: P0 = foundational, P1 = subsequent analytics/ML milestone, P2 = advanced time-series support.

Illustrative Usage

The examples below describe proposed APIs, not methods already available in RepoDB.

Inspect and transform SQL results

DataTable sales = Notebook.Get<DataTable>("Sales");

var cleaned = sales
    .DropNulls("Revenue")
    .Filter(row => row.Field<decimal>("Revenue") > 0)
    .SelectColumns("Country", "Revenue", "Quantity")
    .SortValues("Revenue", ascending: false)
    .Head(100);

var dimensions = cleaned.Shape();
var statistics = cleaned.Describe();
Notebook.Set("CleanedSales", cleaned);

Group and aggregate

var revenueByCountry = sales
    .GroupBy("Country")
    .Aggregate(("Revenue", AggregateFunction.Sum))
    .SortValues("Revenue", ascending: false);

A lightweight DataTableGroupBy intermediate object may be appropriate to support fluent aggregations.

Join results from multiple SQL sections

var combined = customers.Merge(
    orders,
    leftOn: "Id",
    rightOn: "CustomerId",
    how: JoinType.Left);

Here Merge means an in-memory join, not RepoDB's database upsert operation.

Prepare machine-learning data

var (train, test) = customers.TrainTestSplit(testSize: 0.2, seed: 42);

var scaler = new StandardScaler();
scaler.Fit(train, "Revenue", "Quantity");

var scaledTrain = scaler.Transform(train);
var scaledTest = scaler.Transform(test);

Fit preprocessing parameters on training data only to avoid leakage into model evaluation. Consider interoperability with ML.NET IDataView rather than rebuilding model training.

Initial MVP: 30 Methods

Area Methods
Inspection (7) Head, Tail, Sample, Shape, Info, Describe, ValueCounts
Selection (5) SelectColumns, DropColumns, Filter, SortValues, RenameColumns
Cleaning (5) DropNulls, FillNulls, DropDuplicates, Replace, CastColumn
Transformation (3) Assign, Apply, MapColumn
Aggregation (6) GroupBy, Aggregate, Sum, Mean, Min, Max
Combining (2) Merge, Concat
ML preparation (2) TrainTestSplit, ToFeatureMatrix

Technical Considerations

  • Chaining and mutation: Prefer non-mutating operations that return new DataTable instances; expose explicit in-place variants only where justified.
  • Null semantics: Consistently handle DBNull.Value, C# null, grouping keys, comparisons, sorting, and aggregation.
  • Schema fidelity: Preserve relevant DataColumn metadata, CLR types, and nullability. Document behavior for constraints, expressions, relations, and row states.
  • Type conversion: DataColumn.DataType cannot simply be changed on a populated table; CastColumn may need to construct a new table.
  • Performance: Avoid unnecessary full-table clones, consider streaming/chunking for large datasets, and benchmark memory and allocations.
  • Statistics: Specify handling of missing values, numeric conversions, quantile interpolation, and sample versus population variance.
  • ML preprocessing: Support reusable fit/transform objects so the same learned parameters apply to training and test datasets.
  • Notebook integration: SQL and C# sections must exchange named DataTable results safely; transformations should remain reusable outside Studio.
  • Interoperability: Evaluate conversions to ML.NET IDataView, matrices, CSV, JSON, and Parquet.

Acceptance Criteria

  • Introduce a reusable DataTable extension library decoupled from Desktop Studio UI.
  • Implement and document the initial 30-method MVP.
  • Support fluent method chaining and predictable mutation semantics.
  • Support SQL-to-C# Notebook workflows with shared DataTable variables.
  • Define consistent null, type conversion, sorting, and aggregation behavior.
  • Provide unit tests for empty tables, nulls, mixed types, invalid columns, and boundary cases.
  • Add benchmarks for large tables and chained transformations.
  • Document usage examples and the distinction between in-memory Merge and database upsert.
  • Establish a roadmap for advanced statistics, reshaping, time series, and ML.NET integration.

Expected Outcome

RepoDB Desktop Studio users can query data using SQL, manipulate and analyze it using familiar C# DataTable extensions, and prepare it for downstream ML workflows within the same Notebook. The functionality remains available to other .NET applications through a reusable library.

Metadata

Metadata

Assignees

Labels

capabilityenhancementmaintainers-onlyscience

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions