Logical Functions
col_index_from_letters
col_index_from_letters(letter_name)
Translates a letter-style column name (commonly seen in Excel) to its equivalent numerical index value. Args: letter_name (str): the letter-style column name. Should be a string consisting of letters A-Z without spaces. Returns: An integer value Examples: col_index_from_letters('A') -> 1 col_index_from_letters('AA') -> 27
equals
equals(val1, val2)
Returns true if val1 == val2 Args: val1: The first value to compare val2: The second value to compare Returns: True if val1 == val2, and false otherwise
greater_than
greater_than(val1, val2)
Returns true if val1 > val2 Args: val1: The first value to compare val2: The second value to compare Returns: True if val1 > val2, and false otherwise
greater_than_or_equals
greater_than_or_equals(val1, val2)
Returns true if val1 >= val2 Args: val1: The first value to compare val2: The second value to compare Returns: True if val1 >= val2, and false otherwise
if
if(stmt, if_true_val, else_val)
Evaluate whether a logical statement is true or false and return a corresponding value Args: stmt (str): logical statement to be evaluated if_true_val (str): value to return if statement is true else_val (str): value to return if statement is false Returns: Returns `if_true_val` or `else_val` Examples: if(1==2, 'equal', 'not equal') -> 'not equal'
if_error
if_error(statement_to_try, default=None)
Evaluate statement_to_try. If this statement does not result in an exception, return its result. If this statement does result in an exception, return the default statement. If you're familiar with try-catch blocks, you can think of this as a try-catch block. Args: statement_to_try (str): statement to be evaluated default (str): statement to be evaluated in case first_statement results in an exception Returns: the result of the first statement or the result of the second statement. Examples: if_error(echo('PASS'), echo('CATCH')) => 'PASS' if_error(left_pos(INPUT_COL), echo('CATCH')) => 'CATCH' (left_pos will result in an exception)
less_than
less_than(val1, val2)
Returns true if val1 < val2 Args: val1: The first value to compare val2: The second value to compare Returns: True if val1 < val2, and false otherwise
less_than_or_equals
less_than_or_equals(val1, val2)
Returns true if val1 <= val2 Args: val1: The first value to compare val2: The second value to compare Returns: True if val1 <= val2, and false otherwise
lookup
lookup(value_to_lookup, lookup_table_path, key_col=None, value_col=None, sheet_name=None, header_row_index=0, key_col_index=None, value_col_index=None)
Look up value(s) from a lookup table defined in a file One of `key_col` and `key_col_index` must be specified, but not both. One of `value_col` and `value_col_index` must be specified, but not both. Args: value_to_lookup (str): field name (without any quotes) that contains the value lookup_table_path (str): path to a filename containing lookup table key_col (str, optional): column name in the file that contains lookup value See `key_col_index` as an alternative way to specify this. value_col (str, optional): column name in the file which contains the value to be returned See `value_col_index` as an alternative way to specify this. sheet_name (str, optional): Sheet name of an excel sheet (defaults to first sheet) header_row_index (int, optional): The 0-indexed index of the header row in the sheet. Defaults to 0. Specify 'None' if there is no header. key_col_index (int, optional): The 0-indexed index of the column in the file that contains the lookup value. This is an alternative way to specify `key_col`, for example, when there are no headers. value_col_index (int, optional): The 0-indexed index of the column in the file that contains the value to return. This is an alternative way to specify `value_col` (e.g. when there are no headers). Returns: A list of values found from the lookup table, attained by doing the following: 1. Filter to all rows in which the value of the column specified by `key_col`/`key_col_index` equals `value_to_lookup`. 2. For each of the rows from Step 1, get the value of the column specified by `value_col`/`value_col_index`. If no matches are found, returns an empty list. Examples: Given the following: sheet.csv: A B --- --- id1 val1 id2 val2 INPUT_COL contains 'id1' lookup(INPUT_COL, 'sheet.csv', key_col='A', value_col='B') -> ['val1'] lookup(INPUT_COL, 'sheet.csv', key_col_index=0, value_col_index=1) -> ['val1'] Related Functions: lookup_apply(): has similar functionality as lookup() col_index_from_letters_fn(): may be used to create inputs for `key_col_index` or `value_col_index`
lookup_apply
lookup_apply(value_to_lookup, lookup_table_path, key_col=None, value_col=None, sheet_name=None, header_row_index=0, key_col_index=None, value_col_index=None)
Look up formula(s) from a lookup table and return the result(s) of executing them One of `key_col` and `key_col_index` must be specified, but not both. One of `value_col` and `value_col_index` must be specified, but not both. Args: value_to_lookup (str): field name (without any quotes) that contains the value lookup_table_path (str): path to a filename containing lookup table key_col (str, optional): column name in the file that contains lookup value See `key_col_index` as an alternative way to specify this. value_col (str, optional): column name in the file that contains the value to be executed See `value_col_index` as an alternative way to specify this. sheet_name (str, optional): Sheet name of an excel sheet (defaults to first sheet) header_row_index (int, optional): The 0-indexed index of the header row in the sheet. Defaults to 0. Specify 'None' if there is no header. key_col_index (int, optional): The 0-indexed index of the column in the file that contains the lookup value. This is an alternative way to specify `key_col` (e.g. when there are no headers). value_col_index (int, optional): The 0-indexed index of the column in the file that contains the value to return. This is an alternative way to specify `value_col` (e.g. when there are no headers). Returns: A list of results from formulas defined in a lookup table. Specifically, the values are attained by doing the following: 1. Filter to all rows in which the value of the column specified by `key_col`/`key_col_index` equals `value_to_lookup`. 2. For each of the rows from Step 1, get the value of the column specified by `value_col`/`value_col_index`. Each value is expected to be a formula. 3. For each of the formulas from Step 2, invoke the formula and get its result. 4. Return the list of results. If no matches are found in Step 1, returns an empty list. Examples: Given the following: sheet.csv: A B --- ------------------ id1 echo('val1_result') id2 echo('val2_result') INPUT_COL contains 'id1' lookup_apply(INPUT_COL, 'sheet.csv', key_col='A', value_col='B') -> ['val1_result'] lookup_apply(INPUT_COL, 'sheet.csv', key_col_index=0, value_col_index=1) -> ['val1_result'] Related Functions: lookup(): has similar functionality as lookup_apply() col_index_from_letters_fn(): may be used to create inputs for `key_col_index` or `value_col_index`
not_equals
not_equals(val1, val2)
Returns true if val1 != val2 Args: val1: The first value to compare val2: The second value to compare Returns: True if val1 != val2, and false otherwise