def create_adjancency_matrix(db, save_folder='../../data/interim/',
    num_orders=10):
    """
    Create and save a weighted adjacency matrix of the instacart database.

    Args:
        db (Database): The connected instacart database.
        save_folder (str, optional): File location to save the data to. Defaults
            to "../../data/interim/".
        num_orders (int, optional): The number of orders to get interactions from.
            Defaults to 10.

    Raises:
        TypeError: If the number of orders is not an int.
    """
    if not isinstance(num_orders, int):
        raise TypeError('Number of orders must be of type int.')
    query_string = (
        """
        SELECT
            CAST (o.user_id AS INTEGER),
            p.product_id,
            COUNT(p.product_id) AS weight
        FROM
            order_products__prior as p
        INNER JOIN
            (
                SELECT
                    order_id,
                    user_id
                FROM
                    orders
                WHERE
                    eval_set='prior'
                LIMIT
                    {}
            ) AS o
        ON
            o.order_id=p.order_id
        GROUP BY
            o.user_id, p.product_id
        ;
        """
        .format(num_orders))
    df = db.get_dataframe(query_string)
    df.to_csv(save_folder + 'weighted_adjacency_matrix_{}_orders.csv'.
        format(num_orders), index=False)
    prior_orders_query = (
        """
        SELECT
            o.user_id, p.product_id,
            products.department_id, products.aisle_id,
            p.order_id, p.add_to_cart_order,
            p.reordered, o.order_number,
            o.order_dow, o.order_hour_of_day,
            CAST (o.days_since_prior AS INTEGER)
        FROM
            order_products__prior AS p
        INNER JOIN
        (
            SELECT
                user_id, order_id, order_number,
                order_dow, order_hour_of_day,
                days_since_prior
            FROM
                orders
            WHERE
                order_id IN
                (
                    SELECT
                        DISTINCT order_id
                    FROM
                        orders
                    WHERE
                        eval_set='prior'
                    LIMIT
                        {}
                )
        ) AS o
        ON
            o.order_id=p.order_id
        INNER JOIN
            products
        ON
            products.product_id=p.product_id
        ;
    """
        .format(num_orders))
    df = db.get_dataframe(prior_orders_query)
    df.to_csv(save_folder + 'full_info_{}_prior_orders.csv'.format(
        num_orders), index=False)
    db.close()
