Catalog View Reader#

This example shows how to query the generated SQL views through CatalogViewReader and work with the returned pandas DataFrame objects.

import pandas as pd

Setup#

import pandera.pandas as pa

from pandera_catalog import CatalogViewReader, PanderaCatalog, SqlCatalogBackend

Create a SQL-backed catalog#

backend = SqlCatalogBackend(url="sqlite:///catalog.db")
catalog = PanderaCatalog(backend=backend)

catalog.register(
    "sales",
    pa.DataFrameSchema(
        {
            "id": pa.Column(int),
            "value": pa.Column(float, pa.Check.greater_than(0)),
        }
    ),
    tags=["finance"],
    overwrite=True  # for repeated runs of the example
)
catalog.register_projection(
    "sales_reporting",
    [{"schema": "sales", "kind": "columns", "names": ["id", "value"]}],
    overwrite=True  # for repeated runs of the example
)

Query the generated views#

reader = CatalogViewReader(catalog)
schema_catalog: pd.DataFrame = reader.read_schema_catalog()
projection_steps: pd.DataFrame = reader.read_projection_steps()
schema_columns: pd.DataFrame = reader.read_schema_columns()
schema_catalog
schema_name description tags_json is_projected source_projection_name
0 sales None ["finance"] 0 NaN
1 sales_reporting None [] 1 sales_reporting


projection_steps
projection_name step_index kind source_schema_name name_ordinal selected_name
0 sales_reporting 1 columns sales 1 id
1 sales_reporting 1 columns sales 2 value


schema_columns
schema_name column_name ordinal dtype nullable required unique_value coerce regex checks_json is_projected source_projection_name source_schema_name source_column_name
0 sales id 1 int64 None None None None None [] 0 NaN sales id
1 sales value 2 float64 None None None None None [{"greater_than": 0}] 0 NaN sales value
2 sales_reporting id 1 int64 None None None None None [] 1 sales_reporting sales id
3 sales_reporting value 2 float64 None None None None None [{"greater_than": 0}] 1 sales_reporting sales value


Total running time of the script: (0 minutes 0.379 seconds)

Gallery generated by Sphinx-Gallery