gnewcash

Contents:

  • Overview
  • Using GNewCash
  • Code Documentation
    • Account
    • Commodity
    • File Formats
    • GnuCash File
    • GUID Object
    • Search
      • Query
        • Query.all_()
        • Query.any_()
        • Query.average()
        • Query.concat()
        • Query.contains()
        • Query.count()
        • Query.default_if_empty()
        • Query.distinct()
        • Query.element_at()
        • Query.except_()
        • Query.first()
        • Query.group_by()
        • Query.intersect()
        • Query.last()
        • Query.max_()
        • Query.min_()
        • Query.order_by()
        • Query.reset()
        • Query.reverse()
        • Query.select()
        • Query.select_many()
        • Query.single()
        • Query.skip()
        • Query.skip_while()
        • Query.sum_()
        • Query.take()
        • Query.take_while()
        • Query.to_list()
        • Query.union()
        • Query.where()
      • QueryAction
        • QueryAction.perform()
      • SelectQueryAction
        • SelectQueryAction.perform()
      • WhereQueryAction
        • WhereQueryAction.perform()
      • ConcatQueryAction
        • ConcatQueryAction.perform()
      • DistinctQueryAction
        • DistinctQueryAction.perform()
      • ExceptQueryAction
        • ExceptQueryAction.perform()
      • IntersectQueryAction
        • IntersectQueryAction.perform()
      • UnionQueryAction
        • UnionQueryAction.perform()
      • OrderByQueryAction
        • OrderByQueryAction.perform()
      • ReverseQueryAction
        • ReverseQueryAction.perform()
      • GroupByQueryAction
        • GroupByQueryAction.perform()
      • SkipQueryAction
        • SkipQueryAction.perform()
      • SkipWhileQueryAction
        • SkipWhileQueryAction.perform()
      • TakeQueryAction
        • TakeQueryAction.perform()
      • TakeWhileQueryAction
        • TakeWhileQueryAction.perform()
      • InvalidOperationException
    • Slot
    • Transaction
    • Utils
  • Versions
gnewcash
  • Code Documentation
  • Search
  • View page source

Search

class search.Query(collection: Iterable[Any])[source]

Class to handle searching on objects using a LINQ-like format.

all_(predicate: Callable[[Any], bool]) → bool[source]

Determines whether all the elements of a sequence satisfy a condition.

Parameters:

predicate (Callable[[Any], bool]) – Method that takes an element and returns a boolean.

Returns:

True if all elements match the predicate, otherwise false.

Return type:

bool

any_(predicate: Callable[[Any], bool]) → bool[source]

Determines whether any of the elements of a sequence satisfy a condition.

Parameters:

predicate (Callable[[Any], bool]) – Method that takes an element and returns a boolean.

Returns:

True if any elements match the predicate, otherwise false.

Return type:

bool

average() → Any[source]

Calculates the average numeric value of the collection.

Returns:

Average value of the collection, or None if the collection is empty.

Return type:

Any

concat(other: Iterable[Any]) → Query[source]

Concatenates another iterable to the end of the current result set.

Parameters:

other (Iterable[Any]) – Other iterable to include at the end of the current result set.

Returns:

Query object

Return type:

Query

contains(value: Any) → bool[source]

Determines whether any of the elements of a sequence match the provided value.

Parameters:

value (Any) – Value to compare against each element in the sequence.

Returns:

True if any of the collection’s elements matches the value, otherwise False.

Return type:

bool

count() → int[source]

Retrieves the number of elements in the collection.

Returns:

Number of elements in the collection.

Return type:

int

default_if_empty(default: Any) → Any[source]

Returns each element in the collection, using the default if the collection is empty.

Parameters:

default (Any) – Default value to use if the collection is empty.

Returns:

Each element in the collection, or the default value.

Return type:

Any

distinct() → Query[source]

Retrieve unique values from the sequence.

Returns:

Query object

Return type:

Query

element_at(index: int, default: Any | None = None) → Any[source]

Retrieves the element at a specified index from the collection.

Parameters:
  • index (int) – Index of the element to retrieve.

  • default (Any) – Default value to use if there’s not at element at that index.

Returns:

Element at the specified index from the collection.

Return type:

Any

Exception:

IndexError when index is outside of collection and no default value is supplied.

except_(except_values: Iterable[Any]) → Query[source]

Exclude values from the result set.

Parameters:

except_values (Iterable[Any]) – Values to exclude from the result set.

Returns:

Query object

Return type:

Query

first(default: Any | None = None) → Any[source]

Retrieves the first element in the collection.

Parameters:

default (Any) – Default value to use if the collection is empty.

Returns:

First element in the collection.

Return type:

Any

Exception:

IndexError when collection is empty and no default value is supplied.

group_by(key: Callable[[Any], Any], element: Callable[[Any], Any], result: Callable[[Any, Query], Any]) → Query[source]

Groups elements by the provided key, and calls the result function for each key and element.

Parameters:
  • key (Callable[[Any], Any]) – Grouping selector

  • element (Callable[[Any], Any]) – Element selector

  • result (Callable[[Any, Query], Any]) – Result selector

Returns:

Query object

Return type:

Query

intersect(intersect_values: Iterable[Any]) → Query[source]

Only include values from intersect_values in the result set.

Parameters:

intersect_values (Iterable[Any]) – Values to exclusively include in the result set.

Returns:

Query object

Return type:

Query

last(default: Any | None = None) → Any[source]

Retrieves the last element in the collection.

Parameters:

default (Any) – Default value to use if the collection is empty.

Returns:

Last element in the collection.

Return type:

Any

Exception:

IndexError when collection is empty

max_() → Any[source]

Retrieves the maximum value of the elements in the collection.

Returns:

Maximum value of the elements in the collection. Returns None on empty collection.

Return type:

Any

min_() → Any[source]

Retrieves the minimum value of the elements in the collection.

Returns:

Minimum value of the elements in the collection.

Return type:

Any

order_by(order_by: Callable[[Any], Any], descending: bool = False) → Query[source]

Sorts the elements by one or more keys.

Parameters:
  • order_by (Callable[[Any], Any]) – Function that should be passed into “sorted“‘s key field.

  • descending (bool) – Sort the collection in descending order (default false)

Returns:

Query object

Return type:

Query

reset() → None[source]

Clears all stored actions from the query.

reverse() → Query[source]

Return the elements in the reverse order.

Returns:

Query object

Return type:

Query

select(selector: Callable[[Any, int], Any]) → Query[source]

Performs a map on the elements in the collection based on the provided method.

Parameters:

selector (Callable[[Any, int], Any]) – Method that takes an element and an index and returns a new element.

Returns:

Query object

Return type:

Query

select_many(selector: Callable[[Any, int], Any]) → Query[source]

Performs a map on the elements in the collection using the provided method, flattening iterables if applicable.

Parameters:

selector (Callable[[Any, int], Any]) – Method that takes an element and an index and returns a new element.

Returns:

Query object

Return type:

Query

single(default: Any | None = None) → Any[source]

Retrieves a single value from the collection. An error will be thrown if there’s more than one value.

Parameters:

default (Any) – Default value to use if the collection is empty.

Returns:

Single value from the collection.

Return type:

Any

Exception:

IndexError on empty collection (if no default provided), InvalidOperationException if the collection has more than one element.

skip(skip_count: int) → Query[source]

Skips a certain number of elements in the collection.

Parameters:

skip_count (int) – Number of elements to skip.

Returns:

Query object

Return type:

Query

skip_while(predicate: Callable[[Any], bool]) → Query[source]

Skips elements while the predicate’s result for the element is True.

Parameters:

predicate (Callable[[Any], bool]) – Function that returns True if the element should be skipped, otherwise False.

Returns:

Query object

Return type:

Query

sum_() → int[source]

Retrieves the sum of the elements in the collection.

Returns:

Sum of the elements in the collection.

Return type:

int

take(take_count: int) → Query[source]

Takes a certain number of elements in the collection.

Parameters:

take_count (int) – Number of elements to take.

Returns:

Query object

Return type:

Query

take_while(predicate: Callable[[Any], bool]) → Query[source]

Takes elements while the predicate’s result for the element is True.

Parameters:

predicate (Callable[[Any], bool]) – Function that returns True if the element should be taken, otherwise False.

Returns:

Query object

Return type:

Query

to_list() → list[Any][source]

Gets the current query result as a list.

Returns:

Current query result as a list.

Return type:

list[Any]

union(union_values: Iterable[Any]) → Query[source]

Perform a set union on the collection’s elements and the provided values.

Parameters:

union_values (Iterable[Any]) – Values to include along with the collection’s elements.

Returns:

Query object

Return type:

Query

where(predicate: Callable[[Any], bool]) → Query[source]

Filters the collection’s elements based on the provided method.

Parameters:

predicate (Callable[[Any], bool]) – Method that takes an element and returns a boolean (True to include, False to exclude)

Returns:

Query object

Return type:

Query

class search.QueryAction[source]

Base class for other query actions.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Perform the action on the current element in the collection.

class search.SelectQueryAction(selector: Callable[[Any, int], Any], is_select_many: bool)[source]

Class for mapping elements in the collection based on the provided method.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Run the selector against each element and yield it to the next action.

class search.WhereQueryAction(predicate: Callable[[Any], bool])[source]

Class for filtering elements in the collection based on the provided method.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Filter the collection by running each element against the predicate.

class search.ConcatQueryAction(other: Iterable[Any])[source]

Class for concatenating another collection at the end of the current one.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Append the other collection to the end of the current one.

class search.DistinctQueryAction[source]

Class for getting distinct values of elements in the collection.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Filter results based on distinct values.

class search.ExceptQueryAction(exclude_values: Iterable[Any])[source]

Class for filtering out elements that are in a specified collection.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Filter out elements in the collection that are in the specified exclude values.

class search.IntersectQueryAction(intersect_values: Iterable[Any])[source]

Class for only including elements that are in a specified collection.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Perform a set intersection on the collection and the specified values.

class search.UnionQueryAction(union_values: Iterable[Any])[source]

Class for doing a set union on the collection and specified values.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Perform a set union on the collection and the specified values.

class search.OrderByQueryAction(order_by: Callable[[Any], Any], descending: bool)[source]

Class for ordering results by an indicated key.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Sort the collection by the provided key or function, following subsequent then-by instructions.

class search.ReverseQueryAction[source]

Class for reversing the collection.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Reverses the collection.

class search.GroupByQueryAction(key: Callable[[Any], Any], element: Callable[[Any], Any], result: Callable[[Any, Query], Any])[source]

Class for grouping the collection by a provided key.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Groups the collection by the specified key.

class search.SkipQueryAction(skip_count: int)[source]

Class for skipping a certain number of elements.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Skip a certain number of elements.

class search.SkipWhileQueryAction(predicate: Callable[[Any], bool])[source]

Class for skipping elements while a provided predicate is true.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Skip elements while the provided predicate is true.

class search.TakeQueryAction(take_count: int)[source]

Class for taking a certain number of elements.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Take a certain number of elements.

class search.TakeWhileQueryAction(predicate: Callable[[Any], bool])[source]

Class for taking elements while a provided predicate is true.

perform(collection: Iterable[Any]) → Generator[Any, None, None][source]

Take elements while the provided predicate is true.

class search.InvalidOperationException[source]

Exception thrown when an invalid operation was performed.

Previous Next

© Copyright 2018, Paul Bromwell Jr..

Built with Sphinx using a theme provided by Read the Docs.