def coco_categories_dict_from_df(df, category_id_col, category_name_col,
                                 supercategory_col=None):
    """Extract category IDs, category names, and supercat names from df.

    Arguments
    ---------
    df : :class:`pandas.DataFrame`
        A :class:`pandas.DataFrame` of records to filter for category info.
    category_id_col : str
        The name for the column in `df` that contains category IDs.
    category_name_col : str
        The name for the column in `df` that contains category names.
    supercategory_col : str, optional
        The name for the column in `df` that contains supercategory names,
        if one exists. If not provided, supercategory will be left out of the
        output.

    Returns
    -------
    :class:`list` of :class:`dict` s
        A :class:`list` of :class:`dict` s that contain category records per
        the `COCO dataset specification`_ .
    """
    cols_to_keep = [category_id_col, category_name_col]
    rename_dict = {category_id_col: 'id',
                   category_name_col: 'name'}
    if supercategory_col is not None:
        cols_to_keep.append(supercategory_col)
        rename_dict[supercategory_col] = 'supercategory'
    coco_cat_df = df[cols_to_keep]
    coco_cat_df = coco_cat_df.rename(columns=rename_dict)
    coco_cat_df = coco_cat_df.drop_duplicates()

    return coco_cat_df.to_dict(orient='records')