File: underscore.rst

package info (click to toggle)
python-agate 1.13.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,008 kB
  • sloc: python: 8,578; makefile: 126
file content (50 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
=====================
Emulate underscore.js
=====================

filter
======

agate's :meth:`.Table.where` functions exactly like Underscore's :code:`filter`.

.. code-block:: python

    new_table = table.where(lambda row: row['state'] == 'Texas')

reject
======

To simulate Underscore's :code:`reject`, simply negate the return value of the function you pass into agate's :meth:`.Table.where`.

.. code-block:: python

    new_table = table.where(lambda row: not (row['state'] == 'Texas'))

find
====

agate's :meth:`.Table.find` works exactly like Underscore's :code:`find`.

.. code-block:: python

    row = table.find(lambda row: row['state'].startswith('T'))

any
===

The :class:`.Any` aggregation works like Underscore's :code:`any`.

.. code-block:: python

    true_or_false = table.aggregate(Any('salaries', lambda d: d > 100000))

You can also use :meth:`.Table.where` to filter to columns that pass the truth test.

all
===

The :class:`.All` aggregation works like Underscore's :code:`all`.

.. code-block:: python

    true_or_false = table.aggregate(All('salaries', lambda d: d > 100000))