def lookup(name, min_similarity_ratio=.75):
    """
    Look up for a Stan function with similar functionality to a Python
    function (or even an R function, see examples). If the function is
    not present on the lookup table, then attempts to find similar one
    and prints the results. This function requires package `pandas`.

    Parameters
    -----------
    name : str
        Name of the function one wants to look for.
    min_similarity_ratio : float
        In case no exact match is found on the lookup table, the
        function will attempt to find similar names using
        `difflib.SequenceMatcher.ratio()`, and then results with
        calculated ratio below `min_similarity_ratio` will be discarded.

    Examples
    ---------
    #Look up for a Stan function similar to scipy.stats.skewnorm
    lookup("scipy.stats.skewnorm")
    #Look up for a Stan function similar to R dnorm
    lookup("R.dnorm")
    #Look up for a Stan function similar to numpy.hstack
    lookup("numpy.hstack")
    #List Stan log probability mass functions
    lookup("lpmfs")
    #List Stan log cumulative density functions
    lookup("lcdfs")

    Returns
    ---------
    A pandas.core.frame.DataFrame if exact or at least one similar
    result is found, None otherwise.
    """
    if lookuptable is None:
        build()
    if name not in lookuptable.keys():
        from difflib import SequenceMatcher
        from operator import itemgetter
        print("No match for " + name + " in the lookup table.")

        lkt_keys = list(lookuptable.keys())
        mapfunction = lambda x: SequenceMatcher(a=name, b=x).ratio()
        similars = list(map(mapfunction, lkt_keys))
        similars = zip(range(len(similars)), similars)
        similars = list(filter(lambda x: x[1] >= min_similarity_ratio,
                               similars))
        similars = sorted(similars, key=itemgetter(1))

        if (len(similars)):
            print("But the following similar entries were found: ")
            for i in range(len(similars)):
                print(lkt_keys[similars[i][0]] + " ===> with similary "
                      "ratio of " + str(round(similars[i][1], 3)) + "")
            print("Will return results for entry"
                  " " + lkt_keys[similars[i][0]] + " "
                  "(which is the most similar entry found).")
            return lookup(lkt_keys[similars[i][0]])
        else:
            print("And no similar entry found. You may try to decrease"
                  "the min_similarity_ratio parameter.")
        return
    entries = stanftable[lookuptable[name]]
    if not len(entries):
        return "Found no equivalent Stan function available for " + name

    try:
        import pandas as pd
    except ImportError:
        raise ImportError('Package pandas is require to use this '
                          'function.')

    return pd.DataFrame(entries)
def lookup ( name , min_similarity_ratio = .75 ) : if lookuptable is None : build ( ) if name not in lookuptable . keys ( ) : from difflib import SequenceMatcher from operator import itemgetter print ( "No match for " + name + " in the lookup table." ) lkt_keys = list ( lookuptable . keys ( ) ) mapfunction = lambda x : SequenceMatcher ( a = name , b = x ) . ratio ( ) similars = list ( map ( mapfunction , lkt_keys ) ) similars = zip ( range ( len ( similars ) ) , similars ) similars = list ( filter ( lambda x : x [ 1 ] >= min_similarity_ratio , similars ) ) similars = sorted ( similars , key = itemgetter ( 1 ) ) if ( len ( similars ) ) : print ( "But the following similar entries were found: " ) for i in range ( len ( similars ) ) : print ( lkt_keys [ similars [ i ] [ 0 ] ] + " ===> with similary " "ratio of " + str ( round ( similars [ i ] [ 1 ] , 3 ) ) + "" ) print ( "Will return results for entry" " " + lkt_keys [ similars [ i ] [ 0 ] ] + " " "(which is the most similar entry found)." ) return lookup ( lkt_keys [ similars [ i ] [ 0 ] ] ) else : print ( "And no similar entry found. You may try to decrease" "the min_similarity_ratio parameter." ) return entries = stanftable [ lookuptable [ name ] ] if not len ( entries ) : return "Found no equivalent Stan function available for " + name try : import pandas as pd except ImportError : raise ImportError ( 'Package pandas is require to use this ' 'function.' ) return pd . DataFrame ( entries )
Look up for a Stan function with similar functionality to a Python
    function (or even an R function, see examples). If the function is
    not present on the lookup table, then attempts to find similar one
    and prints the results. This function requires package `pandas`.

    Parameters
    -----------
    name : str
        Name of the function one wants to look for.
    min_similarity_ratio : float
        In case no exact match is found on the lookup table, the
        function will attempt to find similar names using
        `difflib.SequenceMatcher.ratio()`, and then results with
        calculated ratio below `min_similarity_ratio` will be discarded.

    Examples
    ---------
    #Look up for a Stan function similar to scipy.stats.skewnorm
    lookup("scipy.stats.skewnorm")
    #Look up for a Stan function similar to R dnorm
    lookup("R.dnorm")
    #Look up for a Stan function similar to numpy.hstack
    lookup("numpy.hstack")
    #List Stan log probability mass functions
    lookup("lpmfs")
    #List Stan log cumulative density functions
    lookup("lcdfs")

    Returns
    ---------
    A pandas.core.frame.DataFrame if exact or at least one similar
    result is found, None otherwise.