Skip to content

API Reference parrot.tools.dataset_manager.sources.composite

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.dataset_manager.sources.composite

View source

CompositeDataSource — virtual dataset that JOINs two or more existing datasets.

Implements the DataSource ABC. Components are materialized independently (respecting their own caching strategy), per-component filters are applied before the JOIN, and sequential pd.merge() calls produce the result.

Key design decisions (from spec):

  • has_builtin_cache = True: DatasetManager skips its Redis layer for the composite result. Components are cached individually by their own sources.
  • Filter propagation: a filter key is applied only to components that contain that column (column-existence check per component).
  • pd.errors.MergeError is captured and re-raised as ValueError with a descriptive message.
  • Circular import avoided via TYPE_CHECKING for DatasetManager reference.

Class CompositeDataSource

Virtual DataSource that JOINs existing datasets on demand.

Components are fetched independently and JOINed sequentially using pd.merge(). Per-component filters are applied before each JOIN: a filter key is only forwarded to a component if that component has a column with that name.

Parameter Type Default Description
name str Dataset name for this composite.
joins List[JoinSpec] Ordered list of JoinSpec objects.
dataset_manager 'DatasetManager' The owning DatasetManager instance.
description str '' Optional human-readable description.

Attributes:

Attribute Type Description
name Name of this composite dataset (used for logging and cache_key).
joins List[JoinSpec] Ordered list of JoinSpec objects describing the JOINs.
component_names List[str] All unique dataset names referenced by the join specs (insertion order).
has_builtin_cache bool Always True — DatasetManager skips Redis for the composite result. Components are cached individually by their own sources. The JOIN result is recomputed on every fetch() call.
cache_key str Stable cache key derived from the composite name.

Method CompositeDataSource.prefetch_schema

Return a merged schema from all component schemas.

Calls prefetch_schema() on each component source via the DataSource ABC method. If a column appears in multiple components, the last definition wins. Components that fail schema prefetch are skipped with a warning.

prefetch_schema() -> Dict[str, str]

Returns: Dict[str, str] — Dict mapping column names to their type strings.

Method CompositeDataSource.fetch

Materialize all components, apply per-component filters, then JOIN.

fetch(filters: Optional[Dict[str, Any]] = None, **params: Any) -> pd.DataFrame

Parameter Type Default Description
filters Optional[Dict[str, Any]] None Optional dict of equality filters. Scalar values use ==; list/tuple/set values use isin.
**params Any {} Extra keyword arguments forwarded to component materialization. force_refresh is honoured: when True, component caches are bypassed.

Returns: pd.DataFrame — Joined DataFrame.

Raises:

  • ValueError — If a component dataset is not registered.
  • ValueError — If a join column is missing from either side.
  • ValueError — If pd.merge() raises pd.errors.MergeError.

Method CompositeDataSource.describe

Return a human-readable join description for the LLM guide.

describe() -> str

Returns: str — Multi-line string showing each JOIN step and the join key(s).

Alias DataSource

Re-exported from parrot.tools.dataset_manager.sources.base.DataSource.

Alias DatasetManager

Re-exported from parrot.tools.dataset_manager.tool.DatasetManager.

Class JoinSpec

Specification for joining two datasets.

Fields:

Field Type Default Description
left str Left dataset name (must be registered in DatasetManager).
right str Right dataset name (must be registered in DatasetManager).
on Union[str, List[str]] Column name(s) used as join key(s).
how Literal['inner', 'left', 'right', 'outer'] 'inner' Join type — one of "inner", "left", "right", "outer".
suffixes Tuple[str, str] ('' Tuple of suffixes appended to overlapping columns from left and right respectively.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally