Skip to content

feat(stored-dataframes): add the shared format layer for stored dataframe pages - #669

Draft
tkislan wants to merge 2 commits into
mainfrom
tomaskislan/stored-dataframes-package
Draft

tkislan wants to merge 2 commits into
mainfrom
tomaskislan/stored-dataframes-package

Conversation

@tkislan

@tkislan tkislan commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds @deepnote/stored-dataframes, a Node.js-only package that holds the format layer for serving one page of a dataframe that deepnote-toolkit's store_dataframe(df, name) stored, the way GET /v2/projects/:projectId/dataframes/:name answers it. Deepnote Cloud's dataframe API and the vscode-deepnote app preview (deepnote/vscode-deepnote#622) each keep their own copy of this logic today. The API is shaped so both can switch to the package without further changes here.

The package exports:

  • Storage layout: dataframeDirectory for named (deepnote_dataframes/<name>/) and block (.deepnote/dataframes/<notebookId>/<blockId>/) frames, plus the layout constants.
  • Manifest: manifestSchema and parseManifest, which returns null for anything that isn't a valid manifest and ignores extra keys.
  • Page parameters: dataframePageRequestSchema, and dataframePageQuerySchema for HTTP queries (coerced, defaulted and strict).
  • Paging: planDataframePage, which works out which record batches and row ranges a page covers, and slicePageColumns, which joins those ranges into one vector per column.
  • Errors: the error classes and dataframePageErrorResponse. A request error answers 400. A missing or invalid frame answers 404 with Dataframe not found and never the error's detail. A frame or page the server can't serve answers 422. The constructors are public, so a consumer can add its own reasons by subclassing.
  • Encoder: describeColumns and encodeRows, the Arrow-to-JSON value encoder.
    • The JSON-byte and value budgets are optional hooks (chargeJsonBytes, chargeValues). Without them no charge is computed and JSON.stringify is never called.
    • A hook refuses a page by throwing. encodeRows rejects with that same instance, except that an InvalidArrowFileError thrown while a cell is encoded becomes an unreadable_row error.
    • It yields to the event loop as it encodes.

apache-arrow ^21.2.0 is a peer dependency, because the encoder uses instanceof checks against the consumer's apache-arrow classes. The package does no file I/O and registers no compression codec.

Also adds two fixtures under test-fixtures/stored-dataframes/:

  • encoding/: a synthetic pandas/pyarrow frame (30 rows, 17 column types, 3 zstd batches), with its generator script.
  • toolkit_frame/: a frame that deepnote-toolkit 2.9.1 stored.

Testing

  • 267 tests in packages/stored-dataframes:
    • encoder cases with inline-snapshot format checks;
    • hook cases: optional hooks, no JSON.stringify without chargeJsonBytes, and which errors keep their identity and which are wrapped;
    • page-planning edge cases: batch boundaries, empty frames, zero-row batches;
    • end-to-end page reads of both fixtures through apache-arrow.
  • pnpm typecheck, pnpm biome:check, pnpm prettier:check and pnpm --filter @deepnote/stored-dataframes build pass. The build emits ESM and CJS and keeps apache-arrow and zod external.
  • pnpm test: everything passes except 3 cases in packages/cli/src/commands/run.test.ts. Those fail only because this machine has no python binary on PATH, and they pass with one added.
  • The README's usage example typechecks. Run against the toolkit fixture, it answers 200, 400 and 404 as documented.

…rame pages

Add @deepnote/stored-dataframes, a Node.js-only package for serving one page
of a dataframe that deepnote-toolkit's store_dataframe stored, as JSON:

- storage layout and dataframeDirectory for named and block frames
- manifest schema and parseManifest
- page request and HTTP query schemas
- planDataframePage and slicePageColumns
- error classes with dataframePageErrorResponse (400 / 404 / 422)
- describeColumns and encodeRows, the Arrow-to-JSON value encoder, with the
  JSON-byte and value budgets as optional hooks and event-loop yielding

apache-arrow ^21.2.0 is a peer dependency, because the encoder checks
instanceof against the consumer's apache-arrow classes. The package does no
file I/O and registers no compression codec.

Adds two Arrow fixtures under test-fixtures/stored-dataframes/: a synthetic
pandas/pyarrow frame with its generator, and a frame deepnote-toolkit 2.9.1
stored.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
Pre-merge checks: Passed 1

Check name Status Explanation
Updates Docs Passed The PR adds a new feature: the @deepnote/stored-dataframes package. The OSS repo docs for this feature are updated in the PR: - packages/stored-dataframes/README.md (new, 250 lines). It covers ins…
Full details: Updates Docs

Explanation

The PR adds a new feature: the @deepnote/stored-dataframes package. The OSS repo docs for this feature are updated in the PR: - packages/stored-dataframes/README.md (new, 250 lines). It covers installation, stored-frame layout, manifest, page parameters, paging, errors and HTTP status mapping, and the encoder. It also has a usage example. - AGENTS.md. It adds the package to the package list and to the repository routing table. - CONTRIBUTING.md. It adds the package to the repository tree. The docs/ folder is unchanged. This is expected: the feature is a library, and the Deepnote Cloud dataframe API it serves is not documented in this repo. No existing docs/ page describes store_dataframe or the dataframes endpoint. The roadmap is on the landing page of the private deepnote/deepnote-internal repo. That repo is not visible in this run, so I could not check or update it. Reminder: update the roadmap in deepnote/deepnote-internal to reflect the stored-dataframes feature. This is a manual step outside this review.

Resolution

None required for this check. Remaining manual step: update the roadmap on the landing page of the private deepnote/deepnote-internal repo.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.52%. Comparing base (3178097) to head (83f949d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #669      +/-   ##
==========================================
+ Coverage   91.28%   91.52%   +0.23%     
==========================================
  Files         234      241       +7     
  Lines       13600    13979     +379     
  Branches     3876     3965      +89     
==========================================
+ Hits        12415    12794     +379     
  Misses       1182     1182              
  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.

encodeRows built a binary cell's base64 string and only then charged its
length through chargeJsonBytes, so a cell over the caller's JSON budget
allocated 4/3 of its bytes before the hook could refuse it, and a cell past
V8's string limit failed with Node's ERR_STRING_TOO_LONG instead of the
hook's error. encodeBinary now charges the exact JSON length,
4 * ceil(n / 3) + 2, first, as encodeDecimal does for its text. The total
charged per cell is unchanged.

This branch has not been deployed

No deployments
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.

1 participant