Introducing a new way to review your PRs.

Read the announcement

eventual-inc / daft

High-performance data engine for AI and multimodal workloads. Process images, audio, video, and structured data at any scale

View on GitHub

19 documents · Updated Nov 11, 2026

docs / dataframe-api

DataFrame API and lazy workflows

The DataFrame is Daft's public Python table interface. It lets users bring data from memory or external sources into one table model, describe column and table work as a lazy workflow, then run that workflow through a local or distributed engine and return rows, batches, tables, files, or write results.

Public Python surface

The public surface is centered on daft.DataFrame, daft.Expression, and daft.Schema. Most users create a DataFrame with a top-level daft function, build a new DataFrame from each transformation, and use a result method when they need data.

Package entry points

The package root is the main entry point for the table API. It exposes DataFrame creation helpers, column and literal expressions, data types, readers, writers, runners, and session helpers so a normal workflow does not need to know the internal module layout.

Common entry points include:

  • daft.from_pydict() and daft.from_pylist() for Python data.
  • daft.from_arrow() and daft.from_pandas() for local tabular data.
  • daft.from_ray_dataset() and daft.from_dask_dataframe() for compatible distributed data systems.
  • daft.read_parquet(), daft.read_csv(), daft.read_json(), and other readers for external data.
  • daft.from_files() and daft.from_glob_path() for file-oriented sources.
  • Specialized readers such as daft.read_mcap(), daft.read_webdataset(), and the lazy-loaded Lance reader for supported data sources.

The same DataFrame surface applies after each entry point. This gives in-memory data, file data, and table data a common path into lazy planning. See Data model and micropartitions for the data units used after this boundary.

References: daft/__init__.py• L60-166 daft/…/__init__.py• L20-53 daft/…/dataframe.py• L181-206

Schema and column access

The schema is the contract for a DataFrame workflow. df.schema() reports column names and types, while df.column_names and df.columns provide convenient views for programmatic use.

Column access connects table syntax to the expression system. A single lookup such as df["score"] returns an Expression; a multi-column lookup returns a new DataFrame with the selected columns. Later expressions resolve against the current schema, so projections and renames affect which columns are available to later steps.

References: daft/…/dataframe.py• L464-503 daft/…/dataframe.py• L2748-2846 daft/datatype.py• L148-157 daft/…/expressions.py• L138-170

Table transformations

DataFrame methods describe a new result instead of changing the source object in place. The operations cover the main relational and tabular patterns:

Operation groupPurpose
ProjectionSelect, exclude, derive, and rename columns.
Row shapingFilter, limit, offset, remove null or invalid values, sample, and deduplicate rows.
Ordering and layoutSort rows, change work units, or control partition layout.
RelationshipsJoin, as-of join, concatenate, and compare DataFrames with set operations.
ReshapingExplode nested values and change wide or long table form.
AggregationSummarize all rows or group rows before aggregation.

Operations such as joins, global sorts, grouping, and repartitioning can require data from more than one input partition. The API records that need in the workflow so the selected runner can perform the required work later.

References: daft/…/dataframe.py• L2886-2919 daft/…/dataframe.py• L2995-3344 daft/…/dataframe.py• L3920-4122 daft/…/dataframe.py• L4548-4663 daft/…/builder.py• L140-220

Grouped aggregation

Grouped aggregation keeps the grouping step lazy. df.groupby(...) returns a grouped DataFrame that holds the grouping expressions until an aggregate is selected, while global aggregate methods return a DataFrame result directly.

This model lets grouping, derived expressions, and aggregation remain part of one plan. It also gives the optimizer the full workflow when it chooses how to move and reduce data.

References: daft/…/dataframe.py• L5118-5252 daft/…/dataframe.py• L5252-5309 daft/…/builder.py• L208-216

Lazy workflow composition

A lazy workflow records the requested result before it reads or computes all rows. Each DataFrame transformation extends a logical plan and returns another DataFrame, so users can express a complete query with ordinary Python method chaining.

The workflow has a boundary between describing work and asking for a result:

  1. Create a DataFrame from memory, a reader, a table, or a custom source.
  2. Build expressions from columns, literals, functions, and user-defined operations.
  3. Chain DataFrame transformations. Each step extends the logical plan.
  4. Inspect the schema or plan when needed.
  5. Trigger execution through collection, display, iteration, conversion, or a write.
  6. Consume the materialized result or stream it in partitions or Arrow batches.

This diagram shows how a Python workflow becomes data produced by a selected runner.

flowchart LR
    A[Python data or source] --> B[DataFrame]
    B --> C[Expressions and transformations]
    C --> D[Logical plan]
    D --> E[Plan optimization]
    E --> F{Runner}
    F --> G[Native execution]
    F --> H[Ray execution]
    G --> I[Result partitions]
    H --> I
    I --> J[Rows, Arrow, tables, files, or metrics]

Expression composition

An Expression is a deferred description of a value derived from a row, a literal, or an aggregate. daft.col() refers to a column and daft.lit() supplies a constant. Python operators and Daft functions combine these values for projections, filters, sorts, joins, and aggregates.

Expressions also describe casts, null handling, nested fields, windows, aggregates, and user-defined functions. The Python object describes intent; the plan carries that intent to execution instead of computing it when the method is called. See Expressions and functions for the expression language.

References: daft/…/expressions.py• L42-170 daft/…/expressions.py• L216-280 daft/…/dataframe.py• L2995-3028 daft/…/__init__.pyi• L1677-1761

User-defined composition

transform and pipe provide Python composition points around the DataFrame surface. transform is for a function that takes and returns a DataFrame, so a multi-step helper stays in a DataFrame chain. pipe passes the DataFrame to a function and returns that function's result, which can be a non-DataFrame value at an intentional boundary.

User-defined functions expressed through the Daft UDF interface become plan work that the runner can place and execute. This keeps helper code separate from the table API while preserving lazy behavior for DataFrame-returning functions.

References: daft/…/dataframe.py• L273-312 daft/…/dataframe.py• L4665-4679 daft/…/expressions.py• L176-204 daft/…/legacy.py• L488-510

Plan inspection

schema() shows the columns and types that the current workflow will produce. explain() shows how Daft plans to produce them. The default view shows the unoptimized logical plan; the full view adds the optimized logical plan and the physical plan.

Plan inspection helps connect Python operations to execution work without collecting the result. A full plan view runs planning and optimization, but it does not return the data unless a later action executes the workflow.

References: daft/…/dataframe.py• L314-423 daft/…/dataframe.py• L464-485 daft/…/builder.py• L55-95

Execution and materialization

Materialization is the point where a logical workflow becomes data. collect() blocks until the full result is ready and keeps the result partitions and execution metadata available for later access. Preview, conversion, iteration, and write methods also cross the execution boundary when they need data.

Runner selection

The runner is the execution mode for a DataFrame workflow. The native runner is the default local mode; the Ray runner uses Ray to distribute work across a Ray environment. Both consume the same logical DataFrame plan and expose a common result model.

Runner choice is process-wide after a runner is created. Users can set the runner before work starts, or Daft can infer the mode from the environment. Some operations and conversions depend on the selected mode, especially work that needs distributed partitions or Ray objects.

References: daft/…/__init__.py• L22-64 daft/…/__init__.py• L67-136 daft/…/runner.py• L26-70 daft/…/ray_runner.py• L129-191

Materialized and streaming results

collect() materializes the complete result and enables operations that need the final row count. count_rows() runs a count query without requiring the caller to first keep the full result as a materialized DataFrame. show() executes enough work to display a preview and is therefore also an execution action.

The API supports streaming when the consumer does not need all rows in memory:

Result methodResult boundary
iter_rows()Python row dictionaries, one row at a time.
to_arrow_iter()Arrow record batches.
iter_partitions()Daft micropartitions or Ray object references, depending on the runner.
to_arrow(), to_pandas(), to_pydict(), and to_pylist()Complete, blocking conversions.

The result buffer limits how much completed work waits for the consumer. A larger buffer can improve throughput at the cost of memory; a smaller buffer applies more back pressure to execution.

References: daft/…/dataframe.py• L506-741 daft/…/dataframe.py• L3894-3917 daft/…/dataframe.py• L5738-5841 daft/…/dataframe.py• L5861-6009

DataFrame writes

DataFrame writes are blocking endpoints that run the current workflow and send its result to a file format, table system, database, or custom sink. They return a DataFrame that describes written files, table operations, or write metrics, which keeps write results inspectable through the same public surface.

The built-in methods cover common tabular files and external table or service targets. write_sink() provides the general custom path: a sink starts once, receives result partitions, gathers its write results, and finalizes one result partition. Writes are side-effect boundaries rather than lazy transformations, so callers must treat them as execution actions.

References: daft/…/dataframe.py• L909-1014 daft/…/dataframe.py• L1016-1326 daft/…/dataframe.py• L1328-1818 daft/…/dataframe.py• L1818-2316 daft/…/dataframe.py• L2392-2421

Context and session state

The Daft context holds planning, execution, and event settings that affect DataFrame workflows. Users can set these settings globally or use context managers for a temporary scope. Subscribers can observe query and execution events without changing the DataFrame API.

A Session adds catalog, table, view, provider, function, and SQL state around DataFrame work. A DataFrame can be attached as a non-materialized temporary view, which lets SQL resolve it without first writing it to a table.

References: daft/context.py• L29-113 daft/context.py• L116-246 daft/session.py• L74-170 daft/session.py• L176-255

Python and native boundary

The Python package is the user-facing layer for input conversion, API checks, expression construction, plan assembly, display, and result conversion. Native bindings provide the shared expression values, logical plan operations, data types, physical execution, and partition data.

The bridge is plan-based. Python DataFrame methods pass expressions to the Python LogicalPlanBuilder, which forwards them to native plan objects. The selected runner then optimizes the plan, creates physical work, and invokes local native execution or distributed Ray execution. Native results return as Python DataFrame, micropartition, record batch, schema, or metric objects.

This division keeps the public Python surface stable while native code handles data movement and parallel work. It also lets the same workflow use local or distributed execution without changing the user's transformation code.

References: daft/…/dataframe.py• L23-53 daft/…/builder.py• L20-23 daft/…/builder.py• L55-95 daft/…/builder.py• L140-172 daft/…/native_executor.py• L28-78 daft/…/ray_runner.py• L150-191 daft/…/micropartition.py• L37-114

Input and output boundaries

The DataFrame API uses common table contracts at both ends of a workflow. Sources provide a schema and independent read tasks; sinks receive result micropartitions and return a write result. This allows built-in readers and writers and user-defined connectors to use the same execution path.

Source boundary

A DataSource describes a source that can split its input into tasks. Each task reads a portion of the source and yields record batches with the declared schema. Readers can expose file, table, stream, or service data as a lazy DataFrame without loading all rows during DataFrame creation.

Source metadata can also help planning. A source may describe storage partition fields, execution-time clustering, or support for a count pushdown. These declarations affect how much work the plan needs to do, but the source still enters the user workflow as a DataFrame.

References: daft/…/source.py• L27-105 daft/…/source.py• L108-145 daft/…/__init__.py• L21-41 daft/…/dataframe.py• L98-123

Sink boundary

Writes are side-effect boundaries. A built-in write_* method or write_sink() executes the current workflow, sends result partitions to the destination, and returns a DataFrame describing the write or its metrics.

The custom sink contract has four stages: start once, write partitions, gather write results, and finalize one result partition. This lets a sink commit to an external system while preserving a DataFrame-shaped result for downstream inspection.

References: daft/…/dataframe.py• L2392-2421 daft/…/sink.py• L16-45 daft/…/sink.py• L47-111

Result representations

Execution exchanges partitioned tabular data. A MicroPartition presents a schema, columns, record batches, size, and conversion methods to Python; native bindings own the underlying data. Arrow tables and streams, pandas DataFrames, Python mappings, Ray datasets, and framework datasets are interoperability boundaries built from these results.

Use a complete conversion when the consumer needs one in-memory object. Use a streaming result when the consumer can process batches or partitions as they arrive. See Data model and micropartitions for the representation shared by the Python and native layers.

References: daft/…/micropartition.py• L37-70 daft/…/micropartition.py• L77-192 daft/…/dataframe.py• L615-741 daft/…/dataframe.py• L5861-6009 daft/…/partitioning.py• L44-88

The public API is easiest to understand as three connected views:

Change checklist

When these files or sections are changed, remember to consider these:

  • When DataFrame method inputs or return types change, check column-input conversion, schema resolution, and the logical builder methods that receive those values.
  • When a transformation is added, check plan inspection, native plan support, runner behavior, and the schema that downstream expressions see.
  • When a source or sink changes its schema or partition contract, check Arrow, pandas, Ray, and micropartition boundaries.
  • When runner selection or initialization changes, check mode-specific DataFrame guards, streaming results, and conversions that require Ray.
  • When materialization or caching changes, check previews, row counts, iterators, metrics, and failure details exposed after collection.
  • When a custom source or sink contract changes, check task or partition serialization and the native bridge that wraps the result.
  • When a write destination changes, check its returned result schema, blocking behavior, write mode, partition contract, and external table contract.
  • When an idempotent table write changes, check the commit marker, checkpoint state, retry path, and the contract for repeated idempotence keys.

Important failure modes

TriggerConsequenceGuard
Calling len(df) before the DataFrame is materializedA runtime error occurs because the final row count is not known.Call collect() first or use count_rows() for a count query.
Selecting or filtering with a column that is not in the current schemaPlan construction fails because the expression cannot resolve.Inspect schema() after projections and renames.
Creating a runner and then trying to change runner modeThe process keeps the existing runner and the requested mode does not take effect.Set the runner before the first operation that creates it.
Using a runner-specific operation such as repartitioning with the native runnerThe operation is unavailable, raises a mode error, or becomes a no-op.Select the Ray runner before runner initialization when distributed partition control is required.
Consuming to_pylist() or another complete conversion for a large resultAll rows are held in Python memory.Use iter_rows() or to_arrow_iter() for streaming access.
Calling show() on an expensive workflowThe preview starts source and transformation work.Treat show() as execution and use explain() for plan-only inspection.
Passing incompatible schemas to a combine operationThe operation fails instead of producing a valid table.Align column names and types before concatenation or set operations.
Returning a sink result with a schema different from the declared sink schemaSink finalization fails at the custom sink boundary.Keep the declared result schema aligned with finalize() output.
Reusing an idempotence key for different table-write inputsThe destination treats the write as already committed and silently skips new data.Use one stable key for one logical run and do not reuse it for different inputs.
Retrying a table write with a new idempotence keyThe destination can create a duplicate commit or snapshot.Reuse the original idempotence key for retries.

Key files

FileWhy to read it
daft/__init__.pyShows the public package entry points for DataFrames, expressions, readers, runners, sessions, and schemas.
daft/…/dataframe.pyDefines the public DataFrame surface, lazy transformations, materialization, result access, and writes.
daft/…/expressions.pyDefines the Python expression layer used by DataFrame operations.
daft/…/builder.pyShows how Python DataFrame actions become logical plan operations and receive planning settings.
daft/…/source.pyDefines the source and task contract for custom and built-in lazy inputs.
daft/…/sink.pyDefines the custom sink lifecycle and write result contract.
daft/…/runner.pyDefines the common execution contract for complete and streaming results.
daft/…/__init__.pyDefines runner selection and the process-wide runner boundary.
daft/…/native_executor.pyConnects Python execution to the native executor and native result stream.
daft/…/ray_runner.pyShows how distributed execution exposes result partitions and Ray interoperability.
daft/…/micropartition.pyDefines the Python view of partition data used at input, execution, and output boundaries.
daft/session.pyShows how DataFrames, SQL, catalogs, tables, and temporary views share session state.
daft/context.pyDefines planning, execution, event, and subscriber state used by DataFrame workflows.