data
relationalai.semantics
data( data: DataFrame | list[tuple] | list[dict], columns: list[str] | None = None, schema: dict[str, Concept] | None = None,) -> DataCreate a temporary table from in-memory Python or pandas data.
This is a convenience wrapper around Model.data that operates on
the single active model. The returned Data
object acts like a table: you can refer to its columns (e.g., d.a, d["a"])
in select, where, and define. You can also convert it to a
schema via Table.to_schema and use that schema when creating new entities.
If you have more than one model, call Model.data on the specific model instead.
Parameters
Section titled “Parameters”-
(datapandas.DataFrame|list[tuple] |list[dict]) - The input data. Supported forms are:- A pandas
DataFrame - A list of tuples (each tuple is a row)
- A list of dicts (each dict is a row)
- A pandas
-
(columnslist[str], default:None) - Column names to use whendatais a list of tuples. If omitted, the data will use default integer column labels0,1,2, … . Those default labels are exposed ascol0,col1,col2, … so you can writed.col0,d.col1, etc. -
(schemadict[str,Concept], default:None) - Explicit column type overrides. Keys are column names and values areConcepttypes (for exampleIntegerorString). When provided, the type for each named column is taken from this mapping instead of being inferred from the data. Columns not present in the mapping are still inferred from the data as usual.
Returns
Section titled “Returns”Data- A table-like object backed by the provided data.
Raises
Section titled “Raises”relationalai.util.error.RAIException- If there is no active model, or if multiple models exist and the active model would be ambiguous.TypeError- Ifdatacannot be converted into a pandasDataFrame.
Examples
Section titled “Examples”Create data from a list of dicts and use it directly:
>>> from relationalai.semantics import Model, data, define, select>>> m = Model()>>> people_rows = data([... {"name": "Alice", "age": 10},... {"name": "Bob", "age": 30},... {"name": "Charlie", "age": 70},... ])>>> select(people_rows.name, people_rows.age).to_df()Use data to create entities by converting to a schema using Table.to_schema
and passing that schema to Concept.new:
>>> Person = m.Concept("Person")>>> define(Person.new(people_rows.to_schema()))>>> select(Person.name, Person.age).to_df()Provide column names when loading tuple rows:
>>> measurements = data([(0, 72.5), (1, 71.9)], columns=["minute", "temperature"])>>> select(measurements.minute, measurements.temperature).to_df()Referenced By
Section titled “Referenced By”RelationalAI Documentation
├── Build With RelationalAI
│ └── Understand how PyRel works > Build a semantic model
│ └── Declare data sources
│ └── Use inline Python data with Model.data
└── Release Notes
└── Python API Release Notes
├── What’s New in Version 1.0.5
│ └── New Features and Enhancements
└── What’s New in Version 1.0.6
└── Bug Fixes