mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) CONTAINS() and summarising by ChoiceList columns with flattening
Summary: Added CONTAINS 'function' which can be used in lookups Changed LookupMapColumn._row_key_map to use right=set so one row can have many keys when CONTAINS is used. Use CONTAINS to implement group column in summary table, while helper column in source table can reference and create multiple rows in summary table, especially when summarising by ChoiceList columns. Use itertools.product to generate all combinations of lookup keys and groupby values. cleanup Test Plan: Added python unit tests. Reviewers: dsagal Reviewed By: dsagal Subscribers: paulfitz, dsagal Differential Revision: https://phab.getgrist.com/D2900
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# pylint: disable=redefined-builtin, line-too-long
|
||||
from collections import OrderedDict
|
||||
from collections import OrderedDict, namedtuple
|
||||
import os
|
||||
|
||||
import six
|
||||
@@ -150,3 +150,25 @@ def VLOOKUP(table, **field_value_pairs):
|
||||
```
|
||||
"""
|
||||
return table.lookupOne(**field_value_pairs)
|
||||
|
||||
class CONTAINS(namedtuple("CONTAINS", "value")):
|
||||
"""
|
||||
Use this marker with `Table.lookupRecords` to find records
|
||||
where a column contains the given value, e.g:
|
||||
|
||||
MoviesTable.lookupRecords(genre=CONTAINS("Drama"))
|
||||
|
||||
will return records in `MoviesTable` where the column `genre`
|
||||
is a list or other container such as `["Comedy", "Drama"]`,
|
||||
i.e. `"Drama" in $genre`.
|
||||
|
||||
Note that the column being looked up (e.g. `genre`)
|
||||
must have values of a container type such as list, tuple, or set.
|
||||
In particular the values mustn't be strings, e.g. `"Comedy-Drama"` won't match
|
||||
even though `"Drama" in "Comedy-Drama"` is `True` in Python.
|
||||
It also won't match substrings within container elements, e.g. `["Comedy-Drama"]`.
|
||||
"""
|
||||
# While users should apply this marker to values in queries, internally
|
||||
# the marker is moved to the column ID so that the LookupMapColumn knows how to
|
||||
# update its index correctly for that column.
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user