def format_function_call(func_name, *args, **kwargs):
    """
    Formats a function of a PipelineStage or Dataset object to ensure proper
    recording of the function and its arguments. args and kwargs should be
    exactly those passed to the function.

    Parameters
    ----------
    func_name : str
        Name of the stage

    Returns
    -------
    str
        Formatted function call
    """
    out_str = func_name + '('

    if len(args) != 0:
        for a in args:
            out_str += (str)(a) + ', '
    if len(kwargs.keys()) != 0:
        for k in kwargs.keys():
            out_str += ((str)(k) + '=' + (str)(kwargs[k]) + ', ')
    if out_str[-2] == ',':
        out_str = out_str[:-2]
    out_str += ')'

    return out_str