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