id int64 0 190k | prompt stringlengths 21 13.4M | docstring stringlengths 1 12k ⌀ |
|---|---|---|
3,066 | from collections import defaultdict
from collections import OrderedDict
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.data import Commodity
from beancount.core import account
class Transaction(NamedTuple):
"""
A transa... | Return a list of all the tags seen in the given entries. Args: entries: A list of directive instances. Returns: A set of tag strings. |
3,067 | from collections import defaultdict
from collections import OrderedDict
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.data import Commodity
from beancount.core import account
class Transaction(NamedTuple):
"""
A transa... | Return a list of all the unique payees seen in the given entries. Args: entries: A list of directive instances. Returns: A set of payee strings. |
3,068 | from collections import defaultdict
from collections import OrderedDict
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.data import Commodity
from beancount.core import account
class Transaction(NamedTuple):
"""
A transa... | Return a list of all the links seen in the given entries. Args: entries: A list of directive instances. Returns: A set of links strings. |
3,069 | from collections import defaultdict
from collections import OrderedDict
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.data import Commodity
from beancount.core import account
The provided code snippet includes necessary depend... | Return a list of all the unique leaf names at level N in an account hierarchy. Args: account_names: A list of account names (strings) level: The level to cross-cut. 0 is for root accounts. nrepeats: A minimum number of times a leaf is required to be present in the the list of unique account names in order to be returne... |
3,070 | from collections import defaultdict
from collections import OrderedDict
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.data import Commodity
from beancount.core import account
The provided code snippet includes necessary depend... | Return a nested dict of all the unique leaf names. account names are labelled with LABEL=True Args: account_names: An iterable of account names (strings) Returns: A nested OrderedDict of account leafs |
3,071 | from collections import defaultdict
from collections import OrderedDict
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.data import Commodity
from beancount.core import account
The provided code snippet includes necessary depend... | Return the minimum and maximum dates in the list of entries. Args: entries: A list of directive instances. types: An optional tuple of types to restrict the entries to. Returns: A pair of datetime.date dates, the minimum and maximum dates seen in the directives. |
3,072 | from collections import defaultdict
from collections import OrderedDict
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.data import Commodity
from beancount.core import account
The provided code snippet includes necessary depend... | Yield all the years that have at least one entry in them. Args: entries: A list of directive instances. Yields: Unique dates see in the list of directives. |
3,073 | from collections import defaultdict
from collections import OrderedDict
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.data import Commodity
from beancount.core import account
The provided code snippet includes necessary depend... | Get a map of the metadata from a map of entries values. Given a dict of some key to a directive instance (or None), return a mapping of the key to the metadata extracted from each directive, or a default value. This can be used to gather a particular piece of metadata from an accounts map or a commodities map. Args: na... |
3,074 | import collections
from collections.abc import Iterable
from decimal import Decimal
import enum
import re
from beancount.core.number import ZERO
from beancount.core.number import same_sign
from beancount.core.amount import Amount
from beancount.core.position import Cost
from beancount.core.position import Position
from... | Check the invariants of the Inventory. Args: inventory: An instance of Inventory. Returns: True if the invariants are respected. |
3,075 | import re
from decimal import Decimal
from typing import List, Optional
The provided code snippet includes necessary dependencies for implementing the `same_sign` function. Write a Python function `def same_sign(number1, number2)` to solve the following problem:
Return true if both numbers have the same sign. Args: nu... | Return true if both numbers have the same sign. Args: number1: An instance of Decimal. number2: An instance of Decimal. Returns: A boolean. |
3,076 | import re
from decimal import Decimal
from typing import List, Optional
def auto_quantize(number: Decimal, threshold: float) -> Decimal:
"""Automatically quantize the number at a given threshold.
For example, with a threshold of 0.01, this will convert:
20.899999618530273 20.9
20.2900000000000000000... | Given a list of numbers from floats, infer the common quantization. For a series of numbers provided as floats, e.g., prices from a price source, we'd like to infer what the right quantization that should be used to avoid rounding errors above some threshold. from the numbers. This simple algorithm auto-quantizes all t... |
3,077 | import collections
from typing import Optional, Set
from beancount.core.number import ONE
from beancount.core.number import ZERO
from beancount.core.data import Price
from beancount.core.data import Currency
from beancount.core import data
from beancount.utils import misc_utils
from beancount.utils import bisect_key
cl... | Project all prices with a quote currency to another quote currency. Say you have a price for HOOL in USD and you'd like to convert HOOL to CAD. If there aren't any (HOOL, CAD) price pairs in the database it will remain unconverted. Projecting from USD to CAD will compute combined rates and insert corresponding prices o... |
3,078 | import collections
from typing import Optional, Set
from beancount.core.number import ONE
from beancount.core.number import ZERO
from beancount.core.data import Price
from beancount.core.data import Currency
from beancount.core import data
from beancount.utils import misc_utils
from beancount.utils import bisect_key
de... | Return a sorted list of all (date, number) price pairs. Args: price_map: A price map, which is a dict of (base, quote) -> list of (date, number) tuples, as created by build_price_map. base_quote: A pair of strings, the base currency to lookup, and the quote currency to lookup, which expresses which units the base curre... |
3,079 | import collections
import hashlib
from beancount.core.data import Price
from beancount.core import data
def hash_entries(entries, exclude_meta=False):
"""Compute unique hashes of each of the entries and return a map of them.
This is used for comparisons between sets of entries.
Args:
entries: A list o... | Check if a list of entries is included in another list. Args: subset_entries: The set of entries to look for in 'entries'. entries: The larger list of entries that could include 'subset_entries'. Returns: A boolean and a list of missing entries. Raises: ValueError: If a duplicate entry is found. |
3,080 | import collections
import hashlib
from beancount.core.data import Price
from beancount.core import data
def hash_entries(entries, exclude_meta=False):
"""Compute unique hashes of each of the entries and return a map of them.
This is used for comparisons between sets of entries.
Args:
entries: A list o... | Check that a list of entries does not appear in another list. Args: subset_entries: The set of entries to look for in 'entries'. entries: The larger list of entries that should not include 'subset_entries'. Returns: A boolean and a list of entries that are not supposed to appear. Raises: ValueError: If a duplicate entr... |
3,081 | from typing import NamedTuple, Tuple, List, Set, Any, Dict
from decimal import Decimal
import csv
import datetime
import logging
import re
import click
from beancount.core.number import ONE
from beancount.core.number import D
from beancount.core import data
from beancount.core import account
from beancount.core import ... | Produce a Table of per-commodity attributes. |
3,082 | from typing import NamedTuple, Tuple, List, Set, Any, Dict
from decimal import Decimal
import csv
import datetime
import logging
import re
import click
from beancount.core.number import ONE
from beancount.core.number import D
from beancount.core import data
from beancount.core import account
from beancount.core import ... | Produce a Table of per-account attributes. |
3,083 | from typing import NamedTuple, Tuple, List, Set, Any, Dict
from decimal import Decimal
import csv
import datetime
import logging
import re
import click
from beancount.core.number import ONE
from beancount.core.number import D
from beancount.core import data
from beancount.core import account
from beancount.core import ... | Enumerate all the postings. |
3,084 | from typing import NamedTuple, Tuple, List, Set, Any, Dict
from decimal import Decimal
import csv
import datetime
import logging
import re
import click
from beancount.core.number import ONE
from beancount.core.number import D
from beancount.core import data
from beancount.core import account
from beancount.core import ... | Enumerate all the prices seen. |
3,085 | from typing import NamedTuple, Tuple, List, Set, Any, Dict
from decimal import Decimal
import csv
import datetime
import logging
import re
import click
from beancount.core.number import ONE
from beancount.core.number import D
from beancount.core import data
from beancount.core import account
from beancount.core import ... | Enumerate all the exchange rates. |
3,086 | from typing import NamedTuple, Tuple, List, Set, Any, Dict
from decimal import Decimal
import csv
import datetime
import logging
import re
import click
from beancount.core.number import ONE
from beancount.core.number import D
from beancount.core import data
from beancount.core import account
from beancount.core import ... | Join a table with a number of other tables. col_tables is a tuple of (column, table) pairs. |
3,087 | from typing import NamedTuple, Tuple, List, Set, Any, Dict
from decimal import Decimal
import csv
import datetime
import logging
import re
import click
from beancount.core.number import ONE
from beancount.core.number import D
from beancount.core import data
from beancount.core import account
from beancount.core import ... | Reorder the columns of a table to a desired new headers. |
3,088 | from typing import NamedTuple, Tuple, List, Set, Any, Dict
from decimal import Decimal
import csv
import datetime
import logging
import re
import click
from beancount.core.number import ONE
from beancount.core.number import D
from beancount.core import data
from beancount.core import account
from beancount.core import ... | Write a table to a CSV file. |
3,089 | import collections
from beancount.core import account
from beancount.core import amount
from beancount.core import inventory
from beancount.core import data
from beancount.core import position
from beancount.core import flags
from beancount.core import realization
from beancount.utils import misc_utils
from beancount.o... | Insert transaction entries for to fulfill a subsequent balance check. Synthesize and insert Transaction entries right after Pad entries in order to fulfill checks in the padded accounts. Returns a new list of entries. Note that this doesn't pad across parent-child relationships, it is a very simple kind of pad. (I have... |
3,090 | from collections import defaultdict
from beancount.core import data
The provided code snippet includes necessary dependencies for implementing the `filter_tag` function. Write a Python function `def filter_tag(tag, entries)` to solve the following problem:
Yield all the entries which have the given tag. Args: tag: A s... | Yield all the entries which have the given tag. Args: tag: A string, the tag we are interested in. Yields: Every entry in 'entries' that tags to 'tag. |
3,091 | from collections import defaultdict
from beancount.core import data
The provided code snippet includes necessary dependencies for implementing the `filter_link` function. Write a Python function `def filter_link(link, entries)` to solve the following problem:
Yield all the entries which have the given link. Args: link... | Yield all the entries which have the given link. Args: link: A string, the link we are interested in. Yields: Every entry in 'entries' that links to 'link. |
3,092 | from collections import defaultdict
from beancount.core import data
The provided code snippet includes necessary dependencies for implementing the `group_entries_by_link` function. Write a Python function `def group_entries_by_link(entries)` to solve the following problem:
Group the list of entries by link. Args: entr... | Group the list of entries by link. Args: entries: A list of directives/transactions to process. Returns: A dict of link-name to list of entries. |
3,093 | from collections import defaultdict
from beancount.core import data
The provided code snippet includes necessary dependencies for implementing the `get_common_accounts` function. Write a Python function `def get_common_accounts(entries)` to solve the following problem:
Compute the intersection of the accounts on the g... | Compute the intersection of the accounts on the given entries. Args: entries: A list of Transaction entries to process. Returns: A set of strings, the names of the common accounts from these entries. |
3,094 | import collections
from beancount.core.number import ONE
from beancount.core.number import ZERO
from beancount.core.data import Transaction
from beancount.core.data import Balance
from beancount.core import amount
from beancount.core import account
from beancount.core import realization
from beancount.core import gette... | Process the balance assertion directives. For each Balance directive, check that their expected balance corresponds to the actual balance computed at that time and replace failing ones by new ones with a flag that indicates failure. Args: entries: A list of directives. options_map: A dict of options, parsed from the in... |
3,095 | import collections
import datetime
import itertools
from beancount.core import inventory
from beancount.core import data
ONEDAY = datetime.timedelta(days=1)
The provided code snippet includes necessary dependencies for implementing the `get_commodity_lifetimes` function. Write a Python function `def get_commodity_life... | Given a list of directives, figure out the life of each commodity. Args: entries: A list of directives. Returns: A dict of (currency, cost-currency) commodity strings to lists of (start, end) datetime.date pairs. The dates are inclusive of the day the commodity was seen; the end/last dates are one day _after_ the last ... |
3,096 | import collections
import datetime
import itertools
from beancount.core import inventory
from beancount.core import data
The provided code snippet includes necessary dependencies for implementing the `trim_intervals` function. Write a Python function `def trim_intervals(intervals, trim_start=None, trim_end=None)` to s... | Trim a list of date pairs to be within a start and end date. Useful in update-style price fetching. Args: intervals: A list of pairs of datetime.date instances trim_start: An inclusive starting date. trim_end: An exclusive starting date. Returns: A list of new intervals (pairs of (date, date)). |
3,097 | import collections
import datetime
import itertools
from beancount.core import inventory
from beancount.core import data
def compress_intervals_days(intervals, num_days):
"""Compress a list of date pairs to ignore short stretches of unused days.
Args:
intervals: A list of pairs of datetime.date instances.... | Compress a lifetimes map to ignore short stretches of unused days. Args: lifetimes_map: A dict of currency intervals as returned by get_commodity_lifetimes. num_days: An integer, the number of unused days to ignore. Returns: A new dict of lifetimes map where some intervals may have been joined. |
3,098 | import collections
import datetime
import itertools
from beancount.core import inventory
from beancount.core import data
ONE_WEEK = datetime.timedelta(days=7)
The provided code snippet includes necessary dependencies for implementing the `required_weekly_prices` function. Write a Python function `def required_weekly_p... | Enumerate all the commodities and Fridays where the price is required. Given a map of lifetimes for a set of commodities, enumerate all the Fridays for each commodity where it is active. This can be used to connect to a historical price fetcher routine to fill in missing price entries from an existing ledger. Args: lif... |
3,099 | import collections
import datetime
import itertools
from beancount.core import inventory
from beancount.core import data
ONEDAY = datetime.timedelta(days=1)
The provided code snippet includes necessary dependencies for implementing the `required_daily_prices` function. Write a Python function `def required_daily_price... | Enumerate all the commodities and days where the price is required. Given a map of lifetimes for a set of commodities, enumerate all the days for each commodity where it is active. This can be used to connect to a historical price fetcher routine to fill in missing price entries from an existing ledger. Args: lifetimes... |
3,100 | import re
import datetime
from os import path
from collections import namedtuple
from beancount.core import account
from beancount.core import data
from beancount.core import getters
def find_documents(directory, input_filename, accounts_only=None, strict=False):
"""Find dated document files under the given directo... | Check files for document directives and create documents directives automatically. Args: entries: A list of all directives parsed from the file. options_map: An options dict, as is output by the parser. We're using its 'filename' option to figure out relative path to search for documents. Returns: A pair of list of all... |
3,101 | import re
import datetime
from os import path
from collections import namedtuple
from beancount.core import account
from beancount.core import data
from beancount.core import getters
DocumentError = namedtuple('DocumentError', 'source message entry')
The provided code snippet includes necessary dependencies for implem... | Verify that the document entries point to existing files. Args: entries: a list of directives whose documents need to be validated. unused_options_map: A parser options dict. We're not using it. Returns: The same list of entries, and a list of new errors, if any were encountered. |
3,102 | from beancount.core import data
from beancount.ops import summarize
The provided code snippet includes necessary dependencies for implementing the `find_currencies_at_cost` function. Write a Python function `def find_currencies_at_cost(entries, date=None)` to solve the following problem:
Return all currencies that wer... | Return all currencies that were held at cost at some point. This returns all of them, even if not on the books at a particular point in time. This code does not look at account balances. Args: entries: A list of directives. date: A datetime.date instance. Returns: A list of (base, quote) currencies. |
3,103 | from beancount.core import data
from beancount.ops import summarize
def find_currencies_converted(entries, date=None):
"""Return currencies from price conversions.
This function looks at all price conversions that occurred until some date
and produces a list of them. Note: This does not include Price direct... | Return currencies relevant for the given date. This computes the account balances as of the date, and returns the union of: a) The currencies held at cost, and b) Currency pairs from previous conversions, but only for currencies with non-zero balances. This is intended to produce the list of currencies whose prices are... |
3,104 | import datetime
import collections
from beancount.core.number import ZERO
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.account_types import is_income_statement_account
from beancount.core import amount
from beancount.core impo... | Convenience function to open() using an options map. |
3,105 | import datetime
import collections
from beancount.core.number import ZERO
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.account_types import is_income_statement_account
from beancount.core import amount
from beancount.core impo... | Convenience function to close() using an options map. |
3,106 | import datetime
import collections
from beancount.core.number import ZERO
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.account_types import is_income_statement_account
from beancount.core import amount
from beancount.core impo... | Convenience function to clear() using an options map. |
3,107 | import datetime
import collections
from beancount.core.number import ZERO
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.account_types import is_income_statement_account
from beancount.core import amount
from beancount.core impo... | Clamp by getting all the parameters from an options map. See clamp() for details. Args: entries: See clamp(). begin_date: See clamp(). end_date: See clamp(). options_map: A parser's option_map. Returns: Same as clamp(). |
3,108 | import datetime
import collections
from beancount.core.number import ZERO
from beancount.core.data import Transaction
from beancount.core.data import Open
from beancount.core.data import Close
from beancount.core.account_types import is_income_statement_account
from beancount.core import amount
from beancount.core impo... | Close by getting all the parameters from an options map. See cap() for details. Args: entries: See cap(). options_map: A parser's option_map. Returns: Same as close(). |
3,109 | import collections
from decimal import Decimal
from beancount.core.amount import Amount
from beancount.core import data
def merge(entries, prototype_txn):
"""Merge the postings of a list of Transactions into a single one.
Merge postings the given entries into a single entry with the Transaction
attributes o... | Compress multiple transactions into single transactions. Replace consecutive sequences of Transaction entries that fulfill the given predicate by a single entry at the date of the last matching entry. 'predicate' is the function that determines if an entry should be compressed. This can be used to simply a list of tran... |
3,110 | from os import path
import collections
from beancount.core.data import Open
from beancount.core.data import Balance
from beancount.core.data import Close
from beancount.core.data import Transaction
from beancount.core.data import Document
from beancount.core.data import Note
from beancount.core import data
from beancou... | Check constraints on open and close directives themselves. This method checks two kinds of constraints: 1. An open or a close directive may only show up once for each account. If a duplicate is detected, an error is generated. 2. Close directives may only appear if an open directive has been seen previously (chronologi... |
3,111 | from os import path
import collections
from beancount.core.data import Open
from beancount.core.data import Balance
from beancount.core.data import Close
from beancount.core.data import Transaction
from beancount.core.data import Document
from beancount.core.data import Note
from beancount.core import data
from beancou... | Check that balance entries occur only once per day. Because we do not support time, and the declaration order of entries is meant to be kept irrelevant, two balance entries with different amounts should not occur in the file. We do allow two identical balance assertions, however, because this may occur during import. A... |
3,112 | from os import path
import collections
from beancount.core.data import Open
from beancount.core.data import Balance
from beancount.core.data import Close
from beancount.core.data import Transaction
from beancount.core.data import Document
from beancount.core.data import Note
from beancount.core import data
from beancou... | Check that commodity entries are unique for each commodity. Args: entries: A list of directives. unused_options_map: An options map. Returns: A list of new errors, if any were found. |
3,113 | from os import path
import collections
from beancount.core.data import Open
from beancount.core.data import Balance
from beancount.core.data import Close
from beancount.core.data import Transaction
from beancount.core.data import Document
from beancount.core.data import Note
from beancount.core import data
from beancou... | Check that all references to accounts occurs on active accounts. We basically check that references to accounts from all directives other than Open and Close occur at dates the open-close interval of that account. This should be good for all of the directive types where we can extract an account name. Note that this is... |
3,114 | from os import path
import collections
from beancount.core.data import Open
from beancount.core.data import Balance
from beancount.core.data import Close
from beancount.core.data import Transaction
from beancount.core.data import Document
from beancount.core.data import Note
from beancount.core import data
from beancou... | Check the currency constraints from account open declarations. Open directives admit an optional list of currencies that specify the only types of commodities that the running inventory for this account may contain. This function checks that all postings are only made in those commodities. Args: entries: A list of dire... |
3,115 | from os import path
import collections
from beancount.core.data import Open
from beancount.core.data import Balance
from beancount.core.data import Close
from beancount.core.data import Transaction
from beancount.core.data import Document
from beancount.core.data import Note
from beancount.core import data
from beancou... | Check that all filenames in resolved Document entries are absolute filenames. The processing of document entries is assumed to result in absolute paths. Relative paths are resolved at the parsing stage and at point we want to make sure we don't have to do any further processing on them. Args: entries: A list of directi... |
3,116 | from os import path
import collections
from beancount.core.data import Open
from beancount.core.data import Balance
from beancount.core.data import Close
from beancount.core.data import Transaction
from beancount.core.data import Document
from beancount.core.data import Note
from beancount.core import data
from beancou... | Check that all the data types of the attributes of entries are as expected. Users are provided with a means to filter the list of entries. They're able to write code that manipulates those tuple objects without any type constraints. With discipline, this mostly works, but I know better: check, just to make sure. This r... |
3,117 | from os import path
import collections
from beancount.core.data import Open
from beancount.core.data import Balance
from beancount.core.data import Close
from beancount.core.data import Transaction
from beancount.core.data import Document
from beancount.core.data import Note
from beancount.core import data
from beancou... | Check again that all transaction postings balance, as users may have transformed transactions. Args: entries: A list of directives. unused_options_map: An options map. Returns: A list of new errors, if any were found. |
3,118 | import datetime
import re
import beancount
from beancount.parser import _parser
The provided code snippet includes necessary dependencies for implementing the `compute_version_string` function. Write a Python function `def compute_version_string(version, changeset, timestamp)` to solve the following problem:
Compute a... | Compute a version string from the changeset and timestamp baked in the parser. Args: version: A string, the version number. changeset: A string, a version control string identifying the commit of the version. timestamp: An integer, the UNIX epoch timestamp of the changeset. Returns: A human-readable string for the vers... |
3,119 | import collections
import contextlib
import io
from beancount.core.data import new_metadata
from beancount.parser import _parser
def lex_iter(file, builder=None):
"""An iterator that yields all the tokens in the given file.
Args:
file: A string, the filename to run the lexer on, or a file object.
bu... | An iterator that yields all the tokens in the given string. Args: string: a str or bytes, the contents of the ledger to be parsed. Returns: An iterator, see ``lex_iter()`` for details. |
3,120 | import codecs
import datetime
import enum
import io
import re
import sys
import textwrap
from decimal import Decimal
from typing import Optional
from beancount.core import position
from beancount.core import convert
from beancount.core import inventory
from beancount.core import amount
from beancount.core import accoun... | A helper used to align rendered amounts positions to their first currency character (an uppercase letter). This class accepts a list of rendered positions and calculates the necessary width to render them stacked in a column so that the first currency word aligns. It does not go beyond that (further currencies, e.g. fo... |
3,121 | import codecs
import datetime
import enum
import io
import re
import sys
import textwrap
from decimal import Decimal
from typing import Optional
from beancount.core import position
from beancount.core import convert
from beancount.core import inventory
from beancount.core import amount
from beancount.core import accoun... | Render a flag, which can be None, a symbol of a character to a string. |
3,122 | import codecs
import datetime
import enum
import io
import re
import sys
import textwrap
from decimal import Decimal
from typing import Optional
from beancount.core import position
from beancount.core import convert
from beancount.core import inventory
from beancount.core import amount
from beancount.core import accoun... | A convenience function that prints a single error to a file. Args: error: An error object. file: An optional file object to write the errors to. |
3,123 | import codecs
import contextlib
import functools
import inspect
import textwrap
import io
import sys
from beancount.parser import _parser
from beancount.parser import grammar
from beancount.parser import printer
from beancount.parser import hashsrc
from beancount.core import data
from beancount.core.number import MISSI... | Factory of decorators that parse the function's docstring as an argument. Note that the decorators thus generated only run the parser on the tests, not the loader, so is no validation, balance checks, nor plugins applied to the parsed text. Args: expect_errors: A boolean or None, with the following semantics, True: Exp... |
3,124 | import codecs
import contextlib
import functools
import inspect
import textwrap
import io
import sys
from beancount.parser import _parser
from beancount.parser import grammar
from beancount.parser import printer
from beancount.parser import hashsrc
from beancount.core import data
from beancount.core.number import MISSI... | Parse a string with single Beancount directive and replace vars from caller. Args: string: A string with some Beancount input. level: The number of extra stacks to ignore. Returns: A list of entries. Raises: AssertionError: If there are any errors. |
3,125 | import collections
import copy
import traceback
from os import path
from datetime import date
from decimal import Decimal
import regex
from beancount.core.number import ZERO
from beancount.core.number import MISSING
from beancount.core.amount import Amount
from beancount.core import display_context
from beancount.core.... | Build a regexp to validate account names from the options. Args: options: A dict of options, as per beancount.parser.options. Returns: A string, a regular expression that will match all account names. |
3,126 | import collections
import io
import re
import textwrap
from beancount.core.number import D
from beancount.core import data
from beancount.core import account_types
from beancount.core import account
from beancount.core import display_context
The provided code snippet includes necessary dependencies for implementing th... | Validate the options processing mode. Args: value: A string, the value provided as option. Returns: The new value, converted, if the conversion is successful. Raises: ValueError: If the value is invalid. |
3,127 | import collections
import io
import re
import textwrap
from beancount.core.number import D
from beancount.core import data
from beancount.core import account_types
from beancount.core import account
from beancount.core import display_context
The provided code snippet includes necessary dependencies for implementing th... | Validate the plugin option. Args: value: A string, the value provided as option. Returns: The new value, converted, if the conversion is successful. Raises: ValueError: If the value is invalid. |
3,128 | import collections
import io
import re
import textwrap
from beancount.core.number import D
from beancount.core import data
from beancount.core import account_types
from beancount.core import account
from beancount.core import display_context
def D(strord=None):
"""Convert a string into a Decimal object.
This ... | Validate the tolerance option. Args: value: A string, the value provided as option. Returns: The new value, converted, if the conversion is successful. Raises: ValueError: If the value is invalid. |
3,129 | import collections
import io
import re
import textwrap
from beancount.core.number import D
from beancount.core import data
from beancount.core import account_types
from beancount.core import account
from beancount.core import display_context
def D(strord=None):
"""Convert a string into a Decimal object.
This ... | Validate an option with a map of currency/tolerance pairs in a string. Args: value: A string, the value provided as option. Returns: The new value, converted, if the conversion is successful. Raises: ValueError: If the value is invalid. |
3,130 | import collections
import io
import re
import textwrap
from beancount.core.number import D
from beancount.core import data
from beancount.core import account_types
from beancount.core import account
from beancount.core import display_context
The provided code snippet includes necessary dependencies for implementing th... | Validate a boolean option. Args: value: A string, the value provided as option. Returns: The new value, converted, if the conversion is successful. Raises: ValueError: If the value is invalid. |
3,131 | import collections
import io
import re
import textwrap
from beancount.core.number import D
from beancount.core import data
from beancount.core import account_types
from beancount.core import account
from beancount.core import display_context
The provided code snippet includes necessary dependencies for implementing th... | Validate a booking method name. Args: value: A string, the value provided as option. Returns: The new value, converted, if the conversion is successful. Raises: ValueError: If the value is invalid. |
3,132 | import collections
import io
import re
import textwrap
from beancount.core.number import D
from beancount.core import data
from beancount.core import account_types
from beancount.core import account
from beancount.core import display_context
OptDesc = collections.namedtuple(
'OptDesc',
'name default_value examp... | Alternative constructor for OptDesc, with default values. Args: name: See OptDesc. default_value: See OptDesc. example_value: See OptDesc. converter: See OptDesc. deprecated: See OptDesc. alias: See OptDesc. Returns: An instance of OptDesc. |
3,133 | import collections
import io
import re
import textwrap
from beancount.core.number import D
from beancount.core import data
from beancount.core import account_types
from beancount.core import account
from beancount.core import display_context
The provided code snippet includes necessary dependencies for implementing th... | Return the full account name for the unrealized account. Args: options: a dict of ledger options. Returns: A tuple of 2 account objects, one for booking current earnings, and one for current conversions. |
3,134 | import collections
import io
import re
import textwrap
from beancount.core.number import D
from beancount.core import data
from beancount.core import account_types
from beancount.core import account
from beancount.core import display_context
PUBLIC_OPTION_GROUPS = [
OptGroup("""
The title of this ledger / inp... | Produce a formatted text of the available options and their description. Returns: A string, formatted nicely to be printed in 80 columns. |
3,135 | import collections
from beancount.core.number import MISSING
from beancount.core.number import ZERO
from beancount.core import amount
from beancount.core import data
from beancount.core import inventory
from beancount.core import position
from beancount.parser import booking_full
BookingError = collections.namedtuple('... | Validate that no position at cost is allowed to go negative. This routine checks that when a posting reduces a position, existing or not, that the subsequent inventory does not result in a position with a negative number of units. A negative number of units would only be required for short trades of trading spreads on ... |
3,136 | import collections
from beancount.core.number import MISSING
from beancount.core.number import ZERO
from beancount.core import amount
from beancount.core import data
from beancount.core import inventory
from beancount.core import position
from beancount.parser import booking_full
BookingError = collections.namedtuple('... | For all the entries, convert the posting's position's CostSpec to Cost instances. In the simple method, the data provided in the CostSpec must unambiguously provide a way to compute the cost amount. This essentially replicates the way the old parser used to work, but allowing positions to have the fuzzy lot specificati... |
3,137 | import collections
from decimal import Decimal
from beancount.core.number import ZERO
from beancount.core.data import Booking
from beancount.core.amount import Amount
from beancount.core.position import Cost
from beancount.core import flags
from beancount.core import position
from beancount.core import inventory
from b... | Strict booking method, but disambiguate further with sizes. This booking method applies the same algorithm as the STRICT method, but if only one of the ambiguous lots matches the desired size, select that one automatically. |
3,138 | import collections
from decimal import Decimal
from beancount.core.number import ZERO
from beancount.core.data import Booking
from beancount.core.amount import Amount
from beancount.core.position import Cost
from beancount.core import flags
from beancount.core import position
from beancount.core import inventory
from b... | FIFO booking method implementation. |
3,139 | import collections
from decimal import Decimal
from beancount.core.number import ZERO
from beancount.core.data import Booking
from beancount.core.amount import Amount
from beancount.core.position import Cost
from beancount.core import flags
from beancount.core import position
from beancount.core import inventory
from b... | LIFO booking method implementation. |
3,140 | import collections
from decimal import Decimal
from beancount.core.number import ZERO
from beancount.core.data import Booking
from beancount.core.amount import Amount
from beancount.core.position import Cost
from beancount.core import flags
from beancount.core import position
from beancount.core import inventory
from b... | HIFO booking method implementation. |
3,141 | import collections
from decimal import Decimal
from beancount.core.number import ZERO
from beancount.core.data import Booking
from beancount.core.amount import Amount
from beancount.core.position import Cost
from beancount.core import flags
from beancount.core import position
from beancount.core import inventory
from b... | NONE booking method implementation. |
3,142 | import collections
from decimal import Decimal
from beancount.core.number import ZERO
from beancount.core.data import Booking
from beancount.core.amount import Amount
from beancount.core.position import Cost
from beancount.core import flags
from beancount.core import position
from beancount.core import inventory
from b... | AVERAGE booking method implementation. |
3,143 | import collections
import copy
import enum
from decimal import Decimal
import uuid
from beancount.core.number import MISSING
from beancount.core.number import ZERO
from beancount.core.data import Transaction
from beancount.core.data import Booking
from beancount.core.amount import Amount
from beancount.core.position im... | Return a globally unique label for cost entries. |
3,144 | import collections
import copy
import enum
from decimal import Decimal
import uuid
from beancount.core.number import MISSING
from beancount.core.number import ZERO
from beancount.core.data import Transaction
from beancount.core.data import Booking
from beancount.core.amount import Amount
from beancount.core.position im... | Interpolate missing data from the entries using the full historical algorithm. See the internal implementation _book() for details. This method only stripes some of the return values. See _book() for arguments and return values. |
3,145 | import argparse
import hashlib
import textwrap
import types
import warnings
from os import path
def hash_parser_source_files():
"""Compute a unique hash of the parser's Python code in order to bake that into
the extension module. This is used at load-time to verify that the extension
module and the correspo... | Check the extension module's source hash and issue a warning if the current source differs from that of the module. If the source files aren't located in the Python source directory, ignore the warning, we're probably running this from an installed based, in which case we don't need to check anything (this check is use... |
3,146 | import argparse
import hashlib
import textwrap
import types
import warnings
from os import path
def hash_parser_source_files():
"""Compute a unique hash of the parser's Python code in order to bake that into
the extension module. This is used at load-time to verify that the extension
module and the correspo... | Generate an include file for the parser source hash. |
3,147 | import calendar
import collections
import datetime
import decimal
import functools
import io
import itertools
import logging
import math
import operator
import random
import re
import sys
import textwrap
from dateutil import rrule
import click
from beancount.core.number import D
from beancount.core.number import ZERO
f... | Generate the example file. Args: date_birth: A datetime.date instance, the birth date of our character. date_begin: A datetime.date instance, the beginning date at which to generate transactions. date_end: A datetime.date instance, the end date at which to generate transactions. reformat: A boolean, true if we should a... |
3,148 | from typing import List, Tuple
import collections
import logging
import os
import re
import sys
import click
from beancount import loader
from beancount.core import account
from beancount.core import account_types
from beancount.core import compare
from beancount.core import convert
from beancount.core import data
from... | null |
3,149 | from typing import List, Tuple
import collections
import logging
import os
import re
import sys
import click
from beancount import loader
from beancount.core import account
from beancount.core import account_types
from beancount.core import compare
from beancount.core import convert
from beancount.core import data
from... | Dump the lexer output for a Beancount syntax file. |
3,150 | from typing import List, Tuple
import collections
import logging
import os
import re
import sys
import click
from beancount import loader
from beancount.core import account
from beancount.core import account_types
from beancount.core import compare
from beancount.core import convert
from beancount.core import data
from... | Parse the a ledger in debug mode. Run the parser on ledger FILENAME with debug mode active. |
3,151 | from typing import List, Tuple
import collections
import logging
import os
import re
import sys
import click
from beancount import loader
from beancount.core import account
from beancount.core import account_types
from beancount.core import compare
from beancount.core import convert
from beancount.core import data
from... | Round-trip test on arbitrary ledger. Read transactions from ledger FILENAME, print them out, re-read them again and compare them. Both sets of parsed entries should be equal. Both printed files are output to disk, so you can also run diff on them yourself afterwards. |
3,152 | from typing import List, Tuple
import collections
import logging
import os
import re
import sys
import click
from beancount import loader
from beancount.core import account
from beancount.core import account_types
from beancount.core import compare
from beancount.core import convert
from beancount.core import data
from... | Validate a directory hierarchy against the ledger's account names. Read a ledger's list of account names and check that all the capitalized subdirectory names under the given roots match the account names. Args: filename: A string, the Beancount input filename. args: The rest of the arguments provided on the command-li... |
3,153 | from typing import List, Tuple
import collections
import logging
import os
import re
import sys
import click
from beancount import loader
from beancount.core import account
from beancount.core import account_types
from beancount.core import compare
from beancount.core import convert
from beancount.core import data
from... | List available options. |
3,154 | from typing import List, Tuple
import collections
import logging
import os
import re
import sys
import click
from beancount import loader
from beancount.core import account
from beancount.core import account_types
from beancount.core import compare
from beancount.core import convert
from beancount.core import data
from... | List options parsed from a ledger. |
3,155 | from typing import List, Tuple
import collections
import logging
import os
import re
import sys
import click
from beancount import loader
from beancount.core import account
from beancount.core import account_types
from beancount.core import compare
from beancount.core import convert
from beancount.core import data
from... | Describe transaction context. The transaction is looked up in ledger FILENAME at LOCATION. The LOCATION argument is either a line number or a filename:lineno tuple to indicate a location in a ledger included from the main input file. |
3,156 | from typing import List, Tuple
import collections
import logging
import os
import re
import sys
import click
from beancount import loader
from beancount.core import account
from beancount.core import account_types
from beancount.core import compare
from beancount.core import convert
from beancount.core import data
from... | List related transactions. List all transaction in ledger FILENAME linked to LINK or tagged with TAG, or linked to the one at LOCATION, or linked to any transaction in REGION. The LINK and TAG arguments must include the leading ^ or # charaters. The LOCATION argument is either a line number or a filename:lineno tuple t... |
3,157 | from typing import List, Tuple
import collections
import logging
import os
import re
import sys
import click
from beancount import loader
from beancount.core import account
from beancount.core import account_types
from beancount.core import compare
from beancount.core import convert
from beancount.core import data
from... | Print out a list of transactions within REGION and compute balances. The REGION argument is either a stard:end line numbers tuple or a filename:start:end triplet to indicate a region in a ledger file included from the main input file. |
3,158 | from typing import List, Tuple
import collections
import logging
import os
import re
import sys
import click
from beancount import loader
from beancount.core import account
from beancount.core import account_types
from beancount.core import compare
from beancount.core import convert
from beancount.core import data
from... | Print Open directives missing in FILENAME. This can be useful during demos in order to quickly generate all the required Open directives without having to type them manually. |
3,159 | from typing import List, Tuple
import collections
import logging
import os
import re
import sys
import click
from beancount import loader
from beancount.core import account
from beancount.core import account_types
from beancount.core import compare
from beancount.core import convert
from beancount.core import data
from... | Print the precision inferred from the parsed numbers in the input file. |
3,160 | import sys
import types
def check_dependencies():
"""Check the runtime dependencies and report their version numbers.
Returns:
A list of pairs of (package-name, version-number, sufficient) whereby if a
package has not been installed, its 'version-number' will be set to None.
Otherwise, it will... | Check the dependencies and produce a listing on the given file. Args: file: A file object to write the output to. |
3,161 | import collections
import datetime
import functools
from beancount.core import account_types
from beancount.core import amount
from beancount.core import data
from beancount.core.number import ZERO
from beancount.parser import options
ONE_DAY = datetime.timedelta(days=1)
ZERO = Decimal()
The provided code snippet inc... | Check that closed accounts are empty. Args: entries: A list of directives. unused_options_map: An options map. Returns: A list of new errors, if any were found. |
3,162 | import collections
import re
from beancount.core import data
OneCommodityError = collections.namedtuple('OneCommodityError', 'source message entry')
The provided code snippet includes necessary dependencies for implementing the `validate_one_commodity` function. Write a Python function `def validate_one_commodity(entr... | Check that each account has units in only a single commodity. This is an extra constraint that you may want to apply optionally, despite Beancount's ability to support inventories and aggregations with more than one commodity. I believe this also matches GnuCash's model, where each account has a single commodity attach... |
3,163 | import collections
import re
from beancount.core import data
from beancount.core.amount import CURRENCY_RE
ConfigError = collections.namedtuple('ConfigError', 'source message entry')
CheckCommodityError = collections.namedtuple('CheckCommodityError', 'source message entry')
ANONYMOUS = {PRICE_CONTEXT, METADATA_CONTEXT}... | Find all commodities used and ensure they have a corresponding Commodity directive. Args: entries: A list of directives. options_map: An options map. config_str: The configuration as a string version of a float. Returns: A list of new errors, if any were found. |
3,164 | import datetime
from beancount.core.number import ZERO
from beancount.core import data
from beancount.core import amount
ZERO = Decimal()
The provided code snippet includes necessary dependencies for implementing the `check_closing` function. Write a Python function `def check_closing(entries, options_map)` to solve ... | Expand 'closing' metadata to a zero balance check. Args: entries: A list of directives. unused_options_map: An options map. Returns: A list of new errors, if any were found. |
3,165 | import collections
from beancount.core import getters
from beancount.core import data
from beancount.core import realization
LeafOnlyError = collections.namedtuple('LeafOnlyError', 'source message entry')
The provided code snippet includes necessary dependencies for implementing the `validate_leaf_only` function. Writ... | Check for non-leaf accounts that have postings on them. Args: entries: A list of directives. unused_options_map: An options map. Returns: A list of new errors, if any were found. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.