
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/04_backend_view_reader.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_04_backend_view_reader.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_04_backend_view_reader.py:


Catalog View Reader
===================

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

.. GENERATED FROM PYTHON SOURCE LINES 8-9

.. code-block:: Python

    import pandas as pd







.. GENERATED FROM PYTHON SOURCE LINES 10-12

Setup
-----

.. GENERATED FROM PYTHON SOURCE LINES 12-16

.. code-block:: Python

    import pandera.pandas as pa

    from pandera_catalog import CatalogViewReader, PanderaCatalog, SqlCatalogBackend








.. GENERATED FROM PYTHON SOURCE LINES 17-19

Create a SQL-backed catalog
---------------------------

.. GENERATED FROM PYTHON SOURCE LINES 19-39

.. code-block:: Python

    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
    )








.. GENERATED FROM PYTHON SOURCE LINES 40-42

Query the generated views
-------------------------

.. GENERATED FROM PYTHON SOURCE LINES 42-47

.. code-block:: Python

    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()








.. GENERATED FROM PYTHON SOURCE LINES 48-50

.. code-block:: Python

    schema_catalog






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>schema_name</th>
          <th>description</th>
          <th>tags_json</th>
          <th>is_projected</th>
          <th>source_projection_name</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>sales</td>
          <td>None</td>
          <td>["finance"]</td>
          <td>0</td>
          <td>NaN</td>
        </tr>
        <tr>
          <th>1</th>
          <td>sales_reporting</td>
          <td>None</td>
          <td>[]</td>
          <td>1</td>
          <td>sales_reporting</td>
        </tr>
      </tbody>
    </table>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 51-53

.. code-block:: Python

    projection_steps






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>projection_name</th>
          <th>step_index</th>
          <th>kind</th>
          <th>source_schema_name</th>
          <th>name_ordinal</th>
          <th>selected_name</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>sales_reporting</td>
          <td>1</td>
          <td>columns</td>
          <td>sales</td>
          <td>1</td>
          <td>id</td>
        </tr>
        <tr>
          <th>1</th>
          <td>sales_reporting</td>
          <td>1</td>
          <td>columns</td>
          <td>sales</td>
          <td>2</td>
          <td>value</td>
        </tr>
      </tbody>
    </table>
    </div>
    </div>
    <br />
    <br />

.. GENERATED FROM PYTHON SOURCE LINES 54-56

.. code-block:: Python

    schema_columns






.. raw:: html

    <div class="output_subarea output_html rendered_html output_result">
    <div>
    <style scoped>
        .dataframe tbody tr th:only-of-type {
            vertical-align: middle;
        }

        .dataframe tbody tr th {
            vertical-align: top;
        }

        .dataframe thead th {
            text-align: right;
        }
    </style>
    <table border="1" class="dataframe">
      <thead>
        <tr style="text-align: right;">
          <th></th>
          <th>schema_name</th>
          <th>column_name</th>
          <th>ordinal</th>
          <th>dtype</th>
          <th>nullable</th>
          <th>required</th>
          <th>unique_value</th>
          <th>coerce</th>
          <th>regex</th>
          <th>checks_json</th>
          <th>is_projected</th>
          <th>source_projection_name</th>
          <th>source_schema_name</th>
          <th>source_column_name</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>0</th>
          <td>sales</td>
          <td>id</td>
          <td>1</td>
          <td>int64</td>
          <td>None</td>
          <td>None</td>
          <td>None</td>
          <td>None</td>
          <td>None</td>
          <td>[]</td>
          <td>0</td>
          <td>NaN</td>
          <td>sales</td>
          <td>id</td>
        </tr>
        <tr>
          <th>1</th>
          <td>sales</td>
          <td>value</td>
          <td>2</td>
          <td>float64</td>
          <td>None</td>
          <td>None</td>
          <td>None</td>
          <td>None</td>
          <td>None</td>
          <td>[{"greater_than": 0}]</td>
          <td>0</td>
          <td>NaN</td>
          <td>sales</td>
          <td>value</td>
        </tr>
        <tr>
          <th>2</th>
          <td>sales_reporting</td>
          <td>id</td>
          <td>1</td>
          <td>int64</td>
          <td>None</td>
          <td>None</td>
          <td>None</td>
          <td>None</td>
          <td>None</td>
          <td>[]</td>
          <td>1</td>
          <td>sales_reporting</td>
          <td>sales</td>
          <td>id</td>
        </tr>
        <tr>
          <th>3</th>
          <td>sales_reporting</td>
          <td>value</td>
          <td>2</td>
          <td>float64</td>
          <td>None</td>
          <td>None</td>
          <td>None</td>
          <td>None</td>
          <td>None</td>
          <td>[{"greater_than": 0}]</td>
          <td>1</td>
          <td>sales_reporting</td>
          <td>sales</td>
          <td>value</td>
        </tr>
      </tbody>
    </table>
    </div>
    </div>
    <br />
    <br />


.. rst-class:: sphx-glr-timing

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


.. _sphx_glr_download_auto_examples_04_backend_view_reader.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: 04_backend_view_reader.ipynb <04_backend_view_reader.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: 04_backend_view_reader.py <04_backend_view_reader.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: 04_backend_view_reader.zip <04_backend_view_reader.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
