How to use the pydash._ 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 ForestAdmin / forest-django / forest / serializers / serializer_utils.py View on Github external
def is_compound_document_included(self, included, item):
        return _.find(self.payload.get('included', {}), {
            'id': item.get('id'),
            'type': item.get('type')
        })
github dgilland / pydash / src / pydash / numerical.py View on Github external
Returns:
        float: Calculated variance.

    Example:

        >>> variance([1, 18, 20, 4])
        69.6875

    .. versionadded:: 2.1.0
    """
    avg = mean(array)

    def var(x):
        return power(x - avg, 2)

    return pyd._(array).map_(var).mean().value()
github codejamninja / sphinx-markdown-builder / sphinx_markdown_builder / markdown_writer.py View on Github external
def depart_thead(self, node):
        for i in range(len(self.table_entries)):
            length = 0
            for row in self.table_rows:
                if len(row.children) > i:
                    entry_length = len(row.children[i].astext())
                    if entry_length > length:
                        length = entry_length
            self.add('| ' + ''.join(_.map(range(length), lambda: '-')) + ' ')
        self.add('|\n')
        self.table_entries = []
        self.theads.pop()
github madvas / gae-angular-material-starter / main / api / v1 / user_api.py View on Github external
def put(self, key):
        """Updates user's properties"""
        update_properties = ['name', 'bio', 'email', 'location', 'facebook', 'github',
                             'gplus', 'linkedin', 'twitter', 'instagram']
        if auth.is_admin():
            update_properties += ['verified', 'active', 'admin']

        new_data = _.pick(request.json, update_properties)
        g.model_db.populate(**new_data)
        g.model_db.put()
        return make_empty_ok_response()
github ForestAdmin / forest-django / forest / serializers / serializer_utils.py View on Github external
def pick(self, obj, attributes):
        def map_function(value, key):
            return self.key_for_attribute(key)

        return _.map_keys(_.pick(obj, attributes), map_function)
github ForestAdmin / forest-django / forest / serializers / serializer_utils.py View on Github external
def key_for_attribute(self, attribute):
        def transform_callback(acc, value, key):
            if self._is_complex_type(value):
                acc[self.key_for_attribute(key)] = self.key_for_attribute(value)
            else:
                acc[self.key_for_attribute(key)] = value
            return acc, value, key

        def map_function(item):
            if self._is_complex_type(item):
                return self.key_for_attribute(item)
            else:
                return item

        if _.is_dict(attribute):
            return _.transform(attribute, transform_callback)


        elif _.is_list(attribute):
            map(map_function, attribute)

        else:
            if _.is_function(self.opts.get('key_for_attribute')):
                return self.opts['key_for_attribute'](attribute)
            else:
                caserized = inflector.caserize(attribute, self.opts)
                return caserized
github ForestAdmin / forest-django / forest / serializers / serializer_utils.py View on Github external
def serialize_nested(self, dest, current, attribute, opts):

        embeds = []
        attributes = []

        if opts and opts.get('attributes'):
            embeds = filter(lambda x: opts.get(x), opts['attributes'])
            attributes = filter(lambda x: opts.get(x) is None, opts['attributes'])
        else:
            attributes = _.keys(dest)

        ret = {}
        if attributes:
            ret['attributes'] = self.pick(dest, attributes)

        for embed in embeds:
            if self._is_complex_type(dest[embed]):
                self.serialize(ret, dest, embed, opts[embed])

        return ret['attributes']
github ForestAdmin / forest-django / forest / serializers / serializer_utils.py View on Github external
if opts.get('relationship_meta'):
                dest['relationships'][self.key_for_attribute(attribute)]['meta'] = \
                    self.get_meta(current['attribute'], opts['relationship_meta'])
        else:
            if _.is_list(current[attribute]):
                if len(current[attribute]) and _.is_dict(current[attribute][0]):
                    def map_current(item):
                        return self.serialize_nested(item, current, attribute,
                                                    opts)
                    data = map(map_current, current[attribute])
                else:
                    data = current[attribute]

                dest['attributes'][self.key_for_attribute(attribute)] = data
            elif _.is_dict(current[attribute]):
                data = self.serialize_nested(current[attribute], current,
                                            attribute, opts)
                dest['attributes'][self.key_for_attribute(attribute)] = data
            else:
                dest['attributes'][self.key_for_attribute(attribute)] = current[attribute]

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 1 month ago

Package Health Score

91 / 100
Full package analysis