fleche.query
Attributes
Classes
Re-iterable view over a lazy query result. |
Functions
|
Normalise a key argument to a callable. |
Module Contents
- fleche.query._resolve_key(key: str | Callable[[call.LazyCall], Any]) Callable[[call.LazyCall], Any][source]
Normalise a key argument to a callable.
When given a string, produce a lookup on
LazyCall.arguments[key].
- class fleche.query.QueryIterator[source]
Bases:
Iterable[fleche.call.LazyCall]Re-iterable view over a lazy query result.
callsis a zero-argument callable that returns a fresh iterable each time it is invoked. Everyforloop,list(), or consuming method therefore starts a new traversal of the underlying source, so the sameQueryIteratorcan be used multiple times and will reflect the current state of the cache on each pass.- Parameters:
- calls: Callable[[], Iterable[fleche.call.LazyCall]][source]
- __iter__() Iterator[fleche.call.LazyCall][source]
- only() fleche.call.LazyCall[source]
Return the single matching call.
- Raises:
IndexError – if there are no matching calls
ValueError – if there is more than one matching call
- any() fleche.call.LazyCall | None[source]
Return the first matching call, or None if there are no matching calls.
Use .sorted(reverse=…) to control which call is returned when ordering matters.
- take(n: int) QueryIterator[source]
Return first n results as a new QueryIterator (lazy).
- skip(n: int) QueryIterator[source]
Skip first n results and return the rest as a new QueryIterator (lazy).
- filter(predicate: Callable[[fleche.call.LazyCall], bool]) QueryIterator[source]
Return a new QueryIterator keeping only calls where predicate(call) is truthy (lazy).
- sorted(key: str | Callable[[call.LazyCall], Any] | None = None, reverse: bool = False) QueryIterator[source]
Return a new QueryIterator with calls sorted by key.
- Parameters:
key – a callable taking a LazyCall, or a string argument name to sort by
reverse – if True, sort in descending order
- unique(key: str | Callable[[call.LazyCall], Any]) QueryIterator[source]
Return a new QueryIterator with duplicates removed, keeping the first per group (lazy).
- Parameters:
key – a callable taking a LazyCall, or a string argument name to deduplicate by
- groupby(key: str | Callable[[call.LazyCall], Any]) dict[Any, QueryIterator][source]
Partition calls into a dict of QueryIterators keyed by group value.
- Parameters:
key – a callable taking a LazyCall, or a string argument name to group by
- _timestop_extremum(*, reverse: bool) fleche.call.LazyCall[source]
- latest() fleche.call.LazyCall[source]
Return the call with the most recent timestop (requires Runtime metadata).
- Raises:
IndexError – if there are no matching calls
- oldest() fleche.call.LazyCall[source]
Return the call with the oldest timestop (requires Runtime metadata).
- Raises:
IndexError – if there are no matching calls
- transfer(target, pop: bool = False, overwrite: bool = False) None[source]
Replay matching calls into the target cache.
- Parameters:
target – destination
BaseCache.pop – if True, evict transferred calls from the source cache.
overwrite – if True, overwrite entries already present in the target. If False (default), conflicts are skipped.
- table(arguments: Iterable[str] | str | Literal[True] = (), results=False, shrink_keys: bool = True) pandas.DataFrame[source]
Return a pandas DataFrame summarizing queried calls.
Arguments and results are elided.
The DataFrame index will be the lookup key (digest) of each call. Columns are:
name: the function name
module: the module name
‘result`: if results argument is True
metadata fields are flattened and added as columns directly
If given argument names collide with any of the above columns, the are prefixed by ‘a_’. Only requested arguments are loaded from cache.
timestartandtimestopcolumns (produced by theRuntimemetadata) are automatically converted from UTC Unix timestamps (float seconds) to timezone-awarepandas.Timestampobjects in the local timezone.- Parameters:
arguments – add the given arguments (of the queried calls) as columns to the table. Pass
Trueto add all arguments, or a single string as a shortcut for a one-element tuple.results (bool) – if True, add results of queried calls to table
shrink_keys (bool) – if True (default), shrink each lookup key in the index to its shortest unambiguous prefix via the owning cache’s
shrink. Falls back to the full digest if shrinking raisesAmbiguousDigestError. Set toFalseto keep full-length digests (cheaper on large caches).
- Returns:
table of all calls on cache
- Return type:
pandas.DataFrame