Skip to content

[Autoloop] [Autoloop: build-tsb-pandas-typescript-migration] Iteration 6: GroupBy#21

Closed
github-actions[bot] wants to merge 2 commits into
mainfrom
autoloop/build-tsb-pandas-typescript-migration-next-0cac91a2f196d416
Closed

[Autoloop] [Autoloop: build-tsb-pandas-typescript-migration] Iteration 6: GroupBy#21
github-actions[bot] wants to merge 2 commits into
mainfrom
autoloop/build-tsb-pandas-typescript-migration-next-0cac91a2f196d416

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Apr 4, 2026

🤖 This PR is maintained by Autoloop. Each accepted iteration adds a commit to this branch.

Program Goal

Build tsb, a complete TypeScript port of pandas, one feature at a time.

Iteration 6 Summary — GroupBy

Implemented SeriesGroupBy and DataFrameGroupBy — the split-apply-combine engine at the heart of pandas' groupby API.

src/groupby/groupby.ts

SeriesGroupBy (from seriesGroupBy(series, by)):

  • Group by label array, "index" (own index labels), or another Series
  • Aggregations: sum, mean, min, max, count, first, last, std
  • agg(func | builtinName) — uniform aggregation
  • transform(func) — same-shape result (e.g., group demeaning)
  • apply(func) — one scalar per group
  • getGroup(key), Symbol.iterator

DataFrameGroupBy (from dataFrameGroupBy(df, by)):

  • Group by single or multiple column names
  • Same aggregation API as SeriesGroupBy
  • agg(spec) — per-column aggregations ({ score: "sum", weight: "mean" })
  • transform(column, func) — column-wise transform returning same-length Series
  • apply(func), getGroup(key), Symbol.iterator

Built-in aggregations: sum, mean, min, max, count, first, last, std (sample)

tests/groupby/groupby.test.ts — 35+ tests

  • Construction, all aggregations, transform, apply, getGroup, iteration
  • Error handling (unknown keys, length mismatch, unknown agg names)
  • 4 property-based tests with fast-check: sum invariant, count invariant, ngroups bounds, cross-DataFrame sum invariant

playground/groupby.html

Interactive tutorial page covering all GroupBy API.

playground/index.html

GroupBy marked as ✅ Complete in the roadmap.

Metric: pandas_features_ported = 7 (was 6, +1)

Links


🤖 This PR is maintained by Autoloop. Each accepted iteration adds a commit to this branch.

Generated by Autoloop · ● 8.7M ·

github-actions Bot and others added 2 commits April 4, 2026 05:29
Column-oriented 2-D labeled table (pandas.DataFrame) with:
- Three factory methods: fromColumns, fromRecords, from2D
- Shape/ndim/size/empty properties
- Column access: col, get, has
- Slicing: head, tail, iloc, loc
- Column mutations: assign, drop, select, rename
- Missing-value handling: isna, notna, dropna, fillna
- Boolean filter
- Aggregations: sum, mean, min, max, std, count, describe
- Sorting: sortValues (single/multi-column, mixed dirs), sortIndex
- apply (axis=0 column-wise, axis=1 row-wise)
- Iteration: items, iteritems, iterrows
- Conversion: toRecords, toDict, toArray
- Index manipulation: resetIndex, setIndex
- toString (aligned text table)
Full test suite (35+ test cases) and interactive playground page.

Run: https://github.com/githubnext/tsessebe/actions/runs/23971604724

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Implement SeriesGroupBy and DataFrameGroupBy — the split-apply-combine
engine, mirroring pandas.core.groupby.

src/groupby/groupby.ts:
- SeriesGroupBy: group a Series by a label array, index, or another Series
- DataFrameGroupBy: group a DataFrame by one or more column names
- Built-in aggregations: sum, mean, min, max, count, first, last, std
- agg(func | builtinName | spec) for uniform or per-column aggregation
- transform(): same-shape result (e.g., demeaning)
- apply(): arbitrary function returning one scalar per group
- getGroup(key): retrieve a sub-Series or sub-DataFrame for a group
- Symbol.iterator: iterate over [key, group] pairs
- toLabel() helper safely coerces bigint/Date keys to Label-compatible strings

tests/groupby/groupby.test.ts:
- 35+ unit tests covering construction, all aggregations, transform, apply,
  getGroup, iteration, error handling
- 4 property-based tests (fast-check): sum invariant, count invariant, ngroups bounds

playground/groupby.html:
- Full interactive tutorial page for GroupBy

Run: https://github.com/githubnext/tsessebe/actions/runs/23971938070

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant