How to use the pydash.map_ function in pydash

To help you get started, we’ve selected a few pydash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dgilland / pydash / tests / test_utilities.py View on Github external
def test_property_(case, arg, expected):
    assert _.map_(arg, _.property_(case)) == expected
github dgilland / pydash / tests / test_functions.py View on Github external
def test_partial_as_iteratee():
    func = _.partial(lambda offset, value, *args: value + offset, 5)
    case = [1, 2, 3]
    expected = [6, 7, 8]
    _.map_(case, func) == expected
github dgilland / pydash / tests / test_collections.py View on Github external
def test_map_(case, expected, sort_results):
    actual = _.map_(*case)

    if sort_results:
        actual = sorted(actual)

    assert actual == expected
github dgilland / pydash / tests / test_annotations.py View on Github external
def test_annotated_iteratee():
    assert _.map_([1, 2], typed_function) == [2, 3]
github JPStrydom / Crypto-Trading-Bot / src / trader.py View on Github external
:type main_market_filter: str

        :return: All Bittrex markets (with filter applied, if any)
        :rtype: list
        """
        markets = self.Bittrex.get_markets()
        if not markets["success"]:
            error_str = self.Messenger.print_error("market", [], True)
            logger.error(error_str)
            exit()

        markets = markets["result"]
        if main_market_filter is not None:
            market_check = main_market_filter + "-"
            markets = py_.filter_(markets, lambda market: market_check in market["MarketName"])
        markets = py_.map_(markets, lambda market: market["MarketName"])
        return markets
github dgilland / pydash / src / pydash / objects.py View on Github external
Returns:
        dict: Results of omitting properties.

    Example:

        >>> omit_by({'a': 1, 'b': '2', 'c': 3}, lambda v: isinstance(v, int))
        {'b': '2'}

    .. versionadded:: 4.0.0

    .. versionchanged:: 4.2.0
        Support deep paths for `iteratee`.
    """
    if not callable(iteratee):
        paths = pyd.map_(iteratee, to_path)

        if any(len(path) > 1 for path in paths):
            cloned = clone_deep(obj)
        else:
            cloned = to_dict(obj)

        def _unset(obj, path):
            pyd.unset(obj, path)
            return obj

        ret = pyd.reduce_(paths, _unset, cloned)
    else:
        argcount = getargcount(iteratee, maxargs=2)

        ret = {key: value for key, value in iterator(obj)
               if not callit(iteratee, value, key, argcount=argcount)}
github dgilland / pydash / src / pydash / strings.py View on Github external
Example:

        >>> join(['a', 'b', 'c']) == 'abc'
        True
        >>> join([1, 2, 3, 4], '&') == '1&2&3&4'
        True
        >>> join('abcdef', '-') == 'a-b-c-d-e-f'
        True

    .. versionadded:: 2.0.0

    .. versionchanged:: 4.0.0
        Removed alias ``implode``.
    """
    return pyd.to_string(separator).join(pyd.map_(array or (), pyd.to_string))
github joehoeller / Dark-Chocolate / dark_chocolate.py View on Github external
if len(xoxo) > 0 and xoxo[0] != None:
                with open(str(xoxo[0]['output']), 'w') as makefile:
                    for item in xoxo:
                        object_id = str(item['darkchocolate'][0])
                        center_x = str(item['darkchocolate'][1])
                        center_y = str(item['darkchocolate'][2])
                        width = str(item['darkchocolate'][3])
                        height = str(item['darkchocolate'][4])

                        spaces = object_id + " " + center_x + " " + center_y + " " + width + " " + height

                        makefile.write('%s\n' % spaces)


    return _.map_([pos_json for pos_json in os.listdir(_path)
        if pos_json.endswith('.json')],
            lambda x: ingredients(x, _path))
github dgilland / pydash / src / pydash / arrays.py View on Github external
Args:
        array (list): List to map and concatenate.
        iteratee (mixed): Iteratee to apply to each element.

    Returns:
        list: Mapped and concatenated list.

    Example:

        >>> mapcat(range(4), lambda x: list(range(x)))
        [0, 0, 1, 0, 1, 2]

    .. versionadded:: 2.0.0
    """
    return concat(*pyd.map_(array, iteratee))
github ConvLab / ConvLab / convlab / lib / viz.py View on Github external
def create_label(y_col, x_col, title=None, y_title=None, x_title=None, legend_name=None):
    '''Create label dict for go.Layout with smart resolution'''
    legend_name = legend_name or y_col
    y_col_list, x_col_list, legend_name_list = ps.map_(
        [y_col, x_col, legend_name], util.cast_list)
    y_title = str(y_title or ','.join(y_col_list))
    x_title = str(x_title or ','.join(x_col_list))
    title = title or f'{y_title} vs {x_title}'

    label = {
        'y_title': y_title,
        'x_title': x_title,
        'title': title,
        'y_col_list': y_col_list,
        'x_col_list': x_col_list,
        'legend_name_list': legend_name_list,
    }
    return label

pydash

The kitchen sink of Python utility libraries for doing "stuff" in a functional way. Based on the Lo-Dash Javascript library.

MIT
Latest version published 3 months ago

Package Health Score

88 / 100
Full package analysis