ducks package

Subpackages

Submodules

ducks.btree module

class ducks.btree.BTree(d: Dict[Any, Any] | None = None)

Bases: object

Wraps an OOBTree instance. Tweaks it a bit:
  • BTrees len() does a full tree traversal, which is very slow. So we maintain a count instead.

  • BTrees stores None values as if they were just really really small. So “x < 1” will find the Nones. Here instead we disallow None entirely, make it throw TypeError.

  • Provide a nice interface for using >, >=, <, <= to get value ranges.

__getitem__(key)
__init__(d: Dict[Any, Any] | None = None)
get(key, default=None)
get_range(min_key=None, max_key=None, include_min: bool = True, include_max: bool = True) List

Get values in the range of [min_key, max_key]. include_min and include_max determine whether values for the start and end keys will be included.

Examples

Get all values: None, None, True, True Get 1 < key < 10: 1, 10, False, False Get key >= 3: 3, None, True, True

get_range_expr(expr: Dict[str, Any]) List

Get values matching a range expression like {‘>’: 3, ‘<=’: 5}

items()
keys()
values()
ducks.btree.range_expr_to_args(expr: Dict[str, Any]) Tuple[Any, Any, bool, bool]

Turn a range expr into (min_key, max_key, include_min, include_max), which are easier to use with BTrees. e.g., translates {‘<’: 3} into get_values(3, None, True, False). Will ignore keys in expr other than ‘<’, ‘<=’, ‘>’, ‘>=’.

ducks.constants module

class ducks.constants.MatchAnything

Bases: set

ducks.exceptions module

exception ducks.exceptions.AttributeNotFoundError

Bases: Exception

Raised when querying an attribute we don’t have

exception ducks.exceptions.FrozenError

Bases: Exception

Raised when attempting to modify a FrozenDex

exception ducks.exceptions.MissingAttribute

Bases: Exception

Raise this in your attribute functions to denote that the object is missing this attribute. Finds that match the attribute will never return this object. Finds that exclude the attribute will.

ducks.pickling module

ducks.pickling.load(filepath: str) Dex | FrozenDex | ConcurrentDex

Load a Dex, FrozenDex, or ConcurrentDex from a pickle file.

ducks.pickling.save(box: Dex | FrozenDex | ConcurrentDex, filepath: str)

Save a Dex, FrozenDex, or ConcurrentDex to a file.

ducks.utils module

ducks.utils.cyk_intersect(s1: Int64Set, s2: Int64Set) Int64Set

Cykhash intersections are faster on small.intersect(big); handle that appropriately. https://github.com/realead/cykhash/issues/7

ducks.utils.cyk_union(s1: Int64Set, s2: Int64Set) Int64Set

Cykhash unions are faster on big.union(small); handle that appropriately. https://github.com/realead/cykhash/issues/7

ducks.utils.get_attribute(obj: Any, attr: Callable | str) Tuple[Any, bool]

Get the object’s attribute value. Return (value, success). Unsuccessful if attribute is missing.

ducks.utils.get_attributes(cls) List[str]

Helper function to grab the attributes of a class

ducks.utils.make_empty_array(dtype: str)

Shorthand for making a length-0 numpy array.

ducks.utils.split_query(query: Dict) Tuple[Dict, Dict]

Split query into match and exclude terms

ducks.utils.standardize_expr(expr: Any) Dict

Turn a find() expr into a dict of {operator: value}.

ducks.utils.validate_and_standardize_operators(expr: Dict) Dict
ducks.utils.validate_query(indexes: Dict, match: Dict[str | Callable, Any] | None = None, exclude: Dict[str | Callable, Any] | None = None)

Module contents