Skip to content

feat(blocks,convert,runtime-core,mcp): add the pivot-table block type - #524

Merged
tkislan merged 7 commits into
mainfrom
feat/pivot-table-block
Sep 25, 2026
Merged

tkislan merged 7 commits into
mainfrom
feat/pivot-table-block

Conversation

@tkislan

@tkislan tkislan commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds the pivot-table block type to @deepnote/blocks. Deepnote's product ships a pivot table block (docs), but deepnoteBlockSchema had no arm for it. The union is a closed z.discriminatedUnion, so any .deepnote file or snapshot containing one was rejected by deserializeDeepnoteFile, and the product's own export path dropped or rejected it before the file was written.

After this change pivot-table parses, re-serializes with its configuration intact, converts to and from Jupyter/Percent/Quarto/Marimo, executes through runtime-core, and is creatable through the MCP server — the same support level visualization has.

The product consumes this package at ^4.5.1, so the product-side effect follows a release and a dependency bump, not this merge.

Changes

  • Schema — a pivot-table arm after visualizationBlockSchema, PivotTableBlock exported from deepnote-file-schema.ts (not the package index, matching VisualizationBlock), and membership in ExecutableBlock.
  • Codegen — new packages/blocks/src/blocks/pivot-table-blocks.ts reproducing the source the product emits for a pivot cell, dispatched from createPythonCode.
  • Registration — executableBlockTypes in @deepnote/blocks and @deepnote/runtime-core, and CODE_BLOCK_TYPES in @deepnote/convert.
  • Coverage — a repository fixture, codegen tests, converter roundtrips for all four formats, a serialize/deserialize roundtrip, and the MCP deepnote_create case.
  • Docs — blocks-display.md, SKILL.md, packages/blocks/README.md, and a regenerated skills/deepnote/references/schema.ts.

Two deliberate design decisions

deepnote_pivot_* fields are left undeclared. executableBlockMetadataSchema is .passthrough(), so the product's keys survive parse and serialize whatever their current shape — which is what a beta block needs. The consequence: the generated schema.ts renders them as the arm's [k: string]: any, so the hand-written table in blocks-display.md is the only place an agent can learn their names and types.

Codegen disables sanitizePythonVariableName's input_1 fallback, unlike sql-blocks.ts. A SQL block's variable is one the generated code defines; a pivot block reads its variable, so a fallback name would point at a variable the kernel does not have. createPythonCode returns '' instead.

Out of scope

  • Rendering application/vnd.deepnote.pivot-table.v1+json. output-renderer.ts falls through to [Output with MIME types: …] and extractOutputsText yields '', so the MCP run summary omits the block and an agent block running after it in the same run sees an empty ### Output: section. Not an exact parallel to visualization, whose chart output carries a text/plain repr that both surfaces print.
  • Reactivity. AST_ANALYZER_SUPPORTED_CELL_TYPES_LIST omits visualization, and agent was deliberately removed from it in 770f2114.
  • packages/mcp/src/instructions.ts and prompts.ts — confirmed these already omit agent, visualization, notebook-function, input-textarea and input-file, so they are partial lists by design rather than a sync obligation.
  • Package version bumps and publishing — a separate release-branch flow.

Verification

Gate Result
pnpm vitest run --bail=0 3299 passed, +12 new tests all green
pnpm typecheck clean
pnpm biome:check 8 warnings, byte-identical to the pre-change baseline
pnpm prettier:check clean

Three pre-existing failures are unchanged from the baseline, all in packages/cli/src/commands/run.test.ts: they assert pythonEnv: 'python' but the dev box has only python3 on PATH. Unrelated to this change; present on main.

Every new test was watched failing under a realistic mutation before being accepted — removing the createPythonCode branch, removing the union arm, removing pivot-table from CODE_BLOCK_TYPES, removing it from runtime-core's executableBlockTypes, dropping disableEmptyFallback, dropping sanitization, and making the arm's metadata .strip() instead of passthrough. The generated Python was also diffed byte-for-byte against the intended output and ast.parsed as valid Python.

Reviewer note

The codegen template could not be verified against the product's createJupyterSource in deepnote-internal from this environment. Please check the emitted source against libs/shared/src/cells/pivot-table-cell-utils.ts:

import json as _deepnote_json
from IPython.display import display as _deepnote_display

_deepnote_display(
  {
    'application/vnd.deepnote.pivot-table.v1+json': _deepnote_json.loads(_dntk.deepnote_get_data_preview_json(df, '[]', [], 10000, "sampled"))
  },
  raw=True
)

Risk

Additive only — one new union arm, one new module, four list entries. No existing behavior changes; rollback is a revert with no migration. The one-way door is format-level: once a .deepnote file in the wild contains a pivot-table block, an older @deepnote/blocks rejects the whole file. That is inherent to the feature.

🤖 Generated with Claude Code

https://claude.ai/code/session_011qCZn7rQzh55Ty5aXrp8Hn

Summary by CodeRabbit

  • New Features
    • Added beta support for pivot-table display blocks that summarize DataFrame data by configurable rows, columns, values, and aggregation.
    • Pivot-table blocks can execute, are supported in Deepnote files, and are preserved in notebook format conversions.
  • Documentation
    • Added pivot-table block documentation and configuration examples.

Deepnote's product ships a pivot table block, but `deepnoteBlockSchema` had no
arm for it. The union is closed, so any `.deepnote` file or snapshot containing
one was rejected by `deserializeDeepnoteFile`.

`pivot-table` now parses, re-serializes with its configuration intact, converts
to and from Jupyter, Percent, Quarto and Marimo, executes through runtime-core,
and is creatable through the MCP server — the support level `visualization` has.

The `deepnote_pivot_*` metadata fields are deliberately left undeclared: the
block is in beta and `executableBlockMetadataSchema` is `.passthrough()`, so the
product's keys survive a roundtrip whatever their current shape.
`skills/deepnote/references/blocks-display.md` is therefore the only reference
for their names and types, since the generated `schema.ts` renders them as the
arm's `[k: string]: any`.

Codegen disables `sanitizePythonVariableName`'s `input_1` fallback, unlike the
SQL block: a pivot block reads its variable rather than defining it, so a
fallback name would point at a variable the kernel does not have.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qCZn7rQzh55Ty5aXrp8Hn
@codecov

codecov Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.89%. Comparing base (2cf2a2a) to head (4df4241).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #524      +/-   ##
==========================================
+ Coverage   89.86%   89.89%   +0.02%     
==========================================
  Files         207      208       +1     
  Lines       12200    12226      +26     
  Branches     3514     3529      +15     
==========================================
+ Hits        10963    10990      +27     
+ Misses       1234     1233       -1     
  Partials        3        3              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The pivot-table YAML example reused the id and blockGroup of the
big-number example further down the same file. An agent copying both
examples into one .deepnote would produce colliding ids, which the MCP
block lookups reject as an ambiguous prefix.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0189TDaQLJ8fGjXm4EXDXSSv
@coderabbitai

coderabbitai Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: c0f53917-a6f0-4e47-af4e-a01283e7aea7

📥 Commits

Reviewing files that changed from the base of the PR and between 8baf5ff and 4df4241.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 791636f1-df91-4abe-818a-e1a83230ce3d

📥 Commits

Reviewing files that changed from the base of the PR and between 6325a53 and 8baf5ff.

📒 Files selected for processing (1)
  • packages/blocks/src/python-code.test.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The change adds beta pivot-table block support. It defines block schemas and exported types, preserves pivot metadata, generates Python display code with variable-name sanitization and a 10,000-item sample limit, and classifies the block as executable. Tests cover serialization, format conversion, MCP creation, schema validation, and code generation. Documentation and a Deepnote fixture describe pivot-table configuration.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Suggested reviewers: jamesbhobbs, dinohamzic

Merge Risk: ⚪ Minimal · up to 8baf5

The reviewed changes show no established actionable regression that should prevent merging.

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 12 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Updates Docs ✅ Passed Documentation is updated in the OSS repository. The PR adds pivot-table to packages/blocks/README.md, skills/deepnote/SKILL.md, and skills/deepnote/references/blocks-display.md, including its …
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: adding the pivot-table block type across the affected packages.

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 21, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 24, 2026
The switch added in 6bf3e47 had no test, so every line of it was
uncovered and the patch sat below codecov's 80% target. One case per
non-executable block type pins the message it throws, and an unknown
type covers the fall-through that `block satisfies never` rules out at
compile time but not at runtime.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0189TDaQLJ8fGjXm4EXDXSSv
coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 24, 2026
The list in 6325a53 was the switch's case labels retyped, so it could
only ever agree with the implementation. Reading the types off
deepnoteBlockSchema and subtracting the executable ones makes the test
fail when a block type is added to the schema and createPythonCode is
not taught about it.

An empty it.each generates no tests and reports green, so a separate
assertion guards the derivation against silently yielding nothing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0189TDaQLJ8fGjXm4EXDXSSv
@tkislan
tkislan marked this pull request as ready for review September 25, 2026 03:34
@tkislan
tkislan requested a review from a team as a code owner September 25, 2026 03:34
@tkislan
tkislan merged commit 0f53915 into main Sep 25, 2026
22 checks passed
@tkislan
tkislan deleted the feat/pivot-table-block branch September 25, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants