patito.Database.to_relation
- Database.to_relation(derived_from)
Create a new relation object based on data source.
The given data will be represented as a relation associated with the database.
Database(x).to_relation(y)
is equivalent toRelation(y, database=Database(x))
.- Parameters
derived_from (RelationSource) – One of either a polars or pandas
DataFrame
, apathlib.Path
to a parquet or CSV file, a SQL query string, or an existing relation.
Example
>>> import patito as pt >>> db = pt.Database() >>> db.to_relation("select 1 as a, 2 as b").to_df() shape: (1, 2) ┌─────┬─────┐ │ a ┆ b │ │ --- ┆ --- │ │ i64 ┆ i64 │ ╞═════╪═════╡ │ 1 ┆ 2 │ └─────┴─────┘ >>> db.to_relation(pt.DataFrame({"c": [3, 4], "d": ["5", "6"]})).to_df() shape: (2, 2) ┌─────┬─────┐ │ c ┆ d │ │ --- ┆ --- │ │ i64 ┆ str │ ╞═════╪═════╡ │ 3 ┆ 5 │ ├╌╌╌╌╌┼╌╌╌╌╌┤ │ 4 ┆ 6 │ └─────┴─────┘
- Return type
Relation