fleche.query
Classes
Iterator that adds some convenience to plain iterators over calls of 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]Iterator that adds some convenience to plain iterators over calls of query result.
- Parameters:
calls – (iterable of call.LazyCall): underlying results of the query
- calls: 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
- table(arguments: Iterable[str] | str | Literal[True] = (), results=False) 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
- Returns:
table of all calls on cache
- Return type:
pandas.DataFrame