def _sqlite_strata_conditions(df, dtypes, n=1):
    """Given a dataframe where columns are merge_cols and rows are unique
    value combinations that appear as aggregation strata, return a list
    of strings which constitute valid SQLite conditional statements.

    Parameters
    ----------
    df : pandas.core.frame.DataFrame
        A dataframe where columns are merge_cols and rows represent
        unique aggregation strata of the compartment table
    dtypes : Dict[str, str]
        Dictionary to look up SQLite datatype based on column name
    n : int
        Number of rows of the input df to combine in each output
        conditional statement. n=1 means each row of the input will
        correspond to one string in the output list. n=2 means one
        string in the output list is comprised of two rows from the
        input df.

    Returns
    -------
    grouped_conditions : List[str]
        A list of strings, each string being a valid SQLite conditional

    Examples
    --------
    Suppose df looks like this:
        TableNumber | ImageNumber
        =========================
        [1]         | [1]
        [2]         | [1, 2, 3]
        [3]         | [1, 2]
        [4]         | [1]

    >>> _sqlite_strata_conditions(df, dtypes={'TableNumber': 'integer', 'ImageNumber': 'integer'}, n=1)
    ["(TableNumber in (1) and ImageNumber in (1))",
     "(TableNumber in (2) and ImageNumber in (1, 2, 3))",
     "(TableNumber in (3) and ImageNumber in (1, 2))",
     "(TableNumber in (4) and ImageNumber in (1))"]

    >>> _sqlite_strata_conditions(df, dtypes={'TableNumber': 'text', 'ImageNumber': 'integer'}, n=2)
    ["(TableNumber in ('1') and ImageNumber in (1))
      or (TableNumber in ('2') and ImageNumber in (1, 2, 3))",
     "(TableNumber in ('3') and ImageNumber in (1, 2))
      or (TableNumber in ('4') and ImageNumber in (1))"]
    """
    conditions = []
    for row in df.iterrows():
        series = row[1]
        values = [
            [f"'{a}'" for a in y] if dtypes[x] == "text" else y
            for x, y in zip(series.index, series.values)
        ]  # put quotes around text entries
        condition_list = [
            f"{x} in ({', '.join([str(a) for a in y]) if len(y) > 1 else y[0]})"
            for x, y in zip(series.index, values)
        ]
        conditions.append(f"({' and '.join(condition_list)})")
    grouped_conditions = [
        " or ".join(conditions[i : (i + n)]) for i in range(0, len(conditions), n)
    ]
    return grouped_conditions