def _filename_dataset(dataset, market=None, variant=None, extension=None):
    """
    Compose the filename for a dataset given its name, variant, market,
    and filename extension.

    :param dataset: String with dataset name e.g. 'income'.
    :param market: Optional string with dataset market e.g. 'usa'.
    :param variant: Optional string with dataset variant e.g. 'ttm'.
    :param extension: Optional string with filename extension e.g. 'zip' or 'csv'.
    :return: String with filename for the dataset-file.
    """
    assert dataset is not None

    # Compose filename from market and dataset.
    if market is None:
        filename = dataset
    else:
        filename = '{}-{}'.format(market, dataset)

    # Add variant to filename.
    if variant is not None:
        filename = '{}-{}'.format(filename, variant)

    # Add extension to filename.
    if extension is not None:
        filename = '{}.{}'.format(filename, extension)

    return filename