Skip to main content

aip_sdk.from_dataframe

aip_sdk.from_dataframe(df: pd.DataFrame, schema: str, project: Project | None = None, mapping: dict[str, str] | None = None, task_type: str | None = None) -> pd.DataFrame

Map and validate a raw DataFrame to a GDI schema.

This function:

  1. Applies column mapping (renames columns)
  2. Injects a constant task_type column when one is provided and absent
  3. Validates against the GDI schema using Pandera
  4. Attaches the .aip accessor with schema metadata

Parameters

  • df pd.DataFrame: Raw DataFrame
  • schema str: GDI schema name (e.g., 'gdi_text_v1')
  • project Project | None: Optional project for dimension metadata
  • mapping dict[str, str] | None: Column mapping: {raw_column: gdi_column}
  • task_type str | None: Task discriminator for task-scoped schemas (e.g. 'single_turn_llm' for gdi_text_v1). Injected as a constant column when the DataFrame does not already carry one.

Returns

  • pd.DataFrame: Validated DataFrame with .aip accessor attached

Raises

Examples

>>> df = pd.DataFrame(
... {
... "input_id": ["q1"],
... "question": ["What is AI?"],
... "answer": ["Artificial Intelligence"],
... "ref": ["AI is..."],
... }
... )
>>> mapped_df = from_dataframe(
... df,
... schema="gdi_text_v1",
... task_type="single_turn_llm",
... mapping={"question": "prompt", "answer": "sut_response", "ref": "expected_output"},
... )